tags:

views:

170

answers:

1

I have an application, which (for the sake of simplicity) has two types of activities - Overview and DetailView. The Overview activity shows a list of steps and allows the user to start a DetailView activity corresponding to the step chosen.

In the DetailView activity, the user can start another Overview, which shows different steps than the ones in the parent of the current DetailView.

In the Overview, DetailView is started by using startActivityForResult (). In the DetailView, when the user decides to start a second Overview, I call setResult () and finish () and then start the new Overview. In this scenario, onActivityResult () and finishFromChild () do not fire. Instead, they fire when the parent finishes (!?).

I hope that this question isn't too stupid :)

Code from Overview:

        Intent spIntent = new Intent ();
  spIntent.setClassName ("com.testing.testa", "com.testing.testa.Overview");

  spIntent.putExtra("id", itemId);
  spIntent.putExtra("local", isLocal);
  spIntent.putExtra("numberOfSteps", numberOfSteps);
  spIntent.putExtra("currentStep", swipeStepNumber);

  spIntent.putExtra("name", name);

  System.out.println ("swipeStepNum: " + this.swipeStepNumber);
  startActivityForResult (spIntent, 0);

...

public void onActivityResult (int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  System.out.pritnln ("Child ended with resultCode: " + resultCode);     }

Code from DetailView:

Intent spIntent = new Intent ();
spIntent.setClassName ("com.testing.testa", "com.testing.testa.Overview");
spIntent.putExtra("id", itemId);
spIntent.putExtra("name", sectionedAdapter.getItem(position).toString());
startActivity (spIntent);
Intent die = new Intent ();
die.putExtra ("die", true);
setResult (1, die);
finish ();
+1  A: 

In your DetailView, it seems that you are starting a new Overview so you would have O->D->O as your stack of activities. If you comment the startActivity in the DetailView code, you would set the result and call finish(). This should take you back from DetailView (O->D) to the original Overview (O) with the result in onActivityResult. So it seems that you need to decide if you want to go forward with a new Overview or back to the original Overview with the result. You can't go forward to a new Overview and have it see the result. I hope this makes sense.

GrkEngineer
Well, yes, but initially I indeed wanted to start a new overview with the old one finishing itself in the background (when receiving the "finish" result), as that creates a smoother workflow from the user's perspective. I made changes and the problem is no longer relevant to my project, but it is still a curious predicament.
Shade
Ahh, I see. They maybe you could have passed an AsyncTask from the first Activity to the second. It would continue doing the work on a separate thread, and you could handle the result in the new Activity or totally in the background if the UI doesn't need to be changed in the new Activity. Seems like you've moved on, but hope it helps.
GrkEngineer