1

If an activity calls it parent activity by startActivity(intent) // Here intent is parent activity, Then, will a new instance of the parent activty will be opened or the same background activity will come in front?

I'm asking because my parent activity contains a ListView & my child activity is performing an operation that is updating the ListView in parent activity.

As soon as the user presses the Done button in child activity, the list needs to be updated. That's why I'm using startActivity.

reiley
  • 3,759
  • 12
  • 58
  • 114

1 Answers1

2

Instead of using startActivity(intent) in your parent activity, Use startActivityForResult(intent). Doing the way you intend to do will create lot of instances of parent+child activities in your activity stack and that is not good.

In the parent activity, you can just implement onActivityResult() method, and u can update your list.

And the answer to your question, Yes a new instance of the parent activity will be created if you do that.

pixelscreen
  • 1,945
  • 2
  • 18
  • 40
  • You are right but, but here child activity is a `PreferenceActivity`. It is used to check the directories for which user wants to scan for images. And the parentActivity shows the list of images. – reiley Jul 18 '12 at 13:41
  • Don't forget the launching flags in the manifest, you could also clear task to return to the parent, but the method in this answer is better. – ScouseChris Jul 18 '12 at 13:54