I am starting intent to get image from file storage

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);  
startActivityForResult(Intent.createChooser(intent, "Select Picture:"),
Constants.REQUEST_CODE_DOC_PROVIDER);

The UI contains all applications installed on my device of which I am interested in dropbox. When I selected dropBox from drawer to get image I observed log and came to following conclusion please help me to resolve this issue

Case 1 :

  • I choose image and control comes back into activity -> onActivityResult

Case 2 :

  • As soon as I select dropBox option from drawer my activity gets DEAD.
  • dropBox UI is still there when I choose image control comes back to activty but this time oncreate gets called again

Question 1 : why does activity becomes DEAD and onCreate() gets called again when control comes back to activity ?

Question 2 : How to handle this scenario? can this be handled by saving instance state ?

Thank you!

1

There are 1 answers

0
Hai On BEST ANSWER

1) When your calling activity is no longer in the foreground, it may get killed due to memory pressure. When you return to it, it will be recreated.

2) Correct, this is expected and should be handled using onSaveInstanceState. This bundle is then given to you in onCreate: source