0

I have two Activities, A is default launchMode, A start B, launchMode of B is singleInstance, then press home button , onDestroy method of A has been called, why? my device is Pixel 3XL, android version is 12

Guu
  • 129
  • 2
  • 8
  • 1
    The question is: why not? The OS is free to destroy any activity that's not currently in the foreground: https://developer.android.com/guide/components/activities/activity-lifecycle#asem – Thomas Feb 16 '22 at 09:45
  • is this not similar to what you asked a few hours ago https://stackoverflow.com/questions/71126769/redmi-miui-activity-has-been-destroy-with-system – a_local_nobody Feb 16 '22 at 09:46
  • @a_local_nobody I have deleted the issue, I found this issue also happens in android 12 – Guu Feb 16 '22 at 10:07
  • @Thomas but in android 10, A will not be destroyed, only happens in android12, so how can I prevent this from happening – Guu Feb 16 '22 at 10:11
  • You can't. It's how Android works. Read the docs to find out how to deal with it by preserving and restoring state. – Thomas Feb 16 '22 at 10:12
  • Have you set `android:taskAffinity` on any of your `` definitions in the manifest? Please edit your question and post the `` definitions for your activities. – David Wasser Feb 21 '22 at 09:46

0 Answers0