Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android P onStart called before onActivityResult

I am trying the new Android P Developer Preview, and the secenario is as follows:

  1. I call Activity B from Activity A with startActivityForResult
  2. Finish Activity B with SetResult and go back to Activity A, the Activity Life cycle used to be (Prior to Android P Preview):
    1. onActivityResult
    2. onStart
    3. onResume

(Here also a post that confirms this order Execution order of OnActivityResult and OnResume) answer from rndstr

  1. Now While testing the Android P Preview the Activity lifecycle is:

    1. onStart
    2. onActivityResult
    3. onResume

Android Documentation https://developer.android.com/reference/android/app/Activity#onactivityresult says only that onActivityresult should come before onResume, it says nothing about onStart

can anybody help ? is this a bug in Android P Preview or this is a new behavior? is there a good documentation for this?

I am using targetSDK: 23

Activity A is: SingleTask and Activity B is: SingleTop

like image 701
Fadi Selim Avatar asked May 22 '18 12:05

Fadi Selim


1 Answers

It sounds to me like you've answered your own question!

The documentation says only that onActivityResult() will be called before onResume(), it says nothing about onStart().

onStart() and onStop() are only called if your Activity is not visible. This means that if you launch another Activity and that Activity does not completely cover the screen, your Activity will NOT get the onStop(), onRestart() and onStart() calls anyway. Therefore you should not rely on them and you should not rely on the order in which they are called.

like image 120
David Wasser Avatar answered Sep 27 '22 17:09

David Wasser