Search code examples
androidsdkandroid-lifecycle

Launch activity recreating


I am initiating a 3rd party library which is further calling another library sometimes what happens is the main launcher activity is being destroyed and recreated i.e.

their are two SDKs let's SDK1 which uses SDK2

i am calling

MainActivity1 -> SDK1 -> SDK2

and when task is completed MainActivity1 is being recreated no one is calling any finish or anything (i.e flags )

but if i add another activity in between i.e.

MainActivity1 -> MainActivity2 -> SDK1 -> SDK2

MainActivity2 is recreated and MainActivity 1 is also recreated and by recreated i mean onDestroy method is called and also onCreate method is being called again while i am going back to MainActivity1 ideally in this case onCreate should not have been called

can anyone please help in this that why it is happening

Edit:

Is their a possibility where very lard logs are being printed and due these logs memory is going low and hence OS is destroying the activities and hence when we go back in stack those activities are being recreated?


Solution

  • You wrote:

    Is their a possibility where very lard logs are being printed and due these logs memory is going low and hence OS is destroying the activities and hence when we go back in stack those activities are being recreated?

    Yes, this is definitely possible. If there is a low memory situation, Android will kill off activities that are in covered (hidden, "stopped"). When the user returns to those activities, Android will recreate them. You often see this behaviour when an app launches the camera to take a photo or video. Often the calling app's activities will get killed and then recreated upon return to the original app.