0

Suppose you have two activities: A (launcher) and B. Activity A has a button, when you press it, activity B is started for result. When the user presses the back key, in the method onActivityResult() of activity A, put a call to the method recreate(). What happens is that the activity A is recreated, resumed and automatically paused (that is, the onPause() method is called after onResume(), but the activity is fully visible, of course). This happens on the emulator, api level 16,17,18,19,21,22,23. This does not happen on a real api 23 smartphone. You can put a flag inside onActivityResult() and call the recreate() method from onResume() and get the same result. Is this a bug of android emulators or am i missing something? A part of the gradle file:

  compileSdkVersion 27
    defaultConfig {
        applicationId "com.test.test2"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

Update

I see that someone else found the same strange behaviour: stackoverflow question. I think i have added some more info.

berlusca
  • 119
  • 2
  • 9
  • I would investigate your instance control in the manifest. You may be having a single instance allowed where the old one is alive until you relaunch a new version of it, in which case it starts the new one ending the old one. There are a few odd behaviors that can happen depending on how you launch the intent, and your manifest configuration of the activity. Not to say it's not a bug, but often times the Google specific emulators and Google specific phones are more strict on these things where other OEMs may just handle it. – Sam Aug 08 '18 at 19:37
  • @Sam Both activities are singleTop, the intent has no special flags. It is a project started from scratch, just to test this behaviour. – berlusca Aug 08 '18 at 20:28
  • Can you elaborate more on this statement "put a call to the method recreate(). What happens is that the activity A is recreated," I'm not sure what you mean by "put a call to the method recreate(). Are you saying that the onCreate is automatically called? or are you implying something else like you call your own recreate routine? – Sam Aug 09 '18 at 04:20
  • @Sam In A.onActivityResult() (when we return from B to A), call the recreate() method. Or, set some flag to true and call recreate() method from A.onResume(). The recreate() method is a method of the Activity class (of the sdk, not mine). What happens is that the activity A is recreated and resumed, and that is obviously ok, but it is also automatically put in a paused state (the onPause() method is automatically called). – berlusca Aug 09 '18 at 09:14

0 Answers0