Neither
val intent = Intent(sourceActivity, SomeActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(intent)
nor
val intent = Intent(sourceActivity, SomeActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
triggers onNewIntent
as described by official docs:
FLAG_ACTIVITY_NEW_TASK Start the activity in a new task. If a task is already running for the activity you are now starting, that task is brought to the foreground with its last state restored and the activity receives the new intent in onNewIntent(). This produces the same behavior as the "singleTask" launchMode value, discussed in the previous section.
They always try to recreate SomeActivity, calling onCreate
instead!
Expected behaviours:
- SomeActivity, running but not on foreground, paused, is brought back to foreground
- SomeActivity's back stack is preserved
- SomeActivity receives some info - I want to inform SomeActivity of a success/ failure
- SomeActivity instance is reused vs. a duplicated is created anew - so
FLAG_ACTIVITY_SINGLE_TOP
orandroid:launchMode="singleTop"
is not derisable
Interestingly, the Manifest.xml approach works as expected!
<activity
android:name=".webview.SomeActivity"
android:launchMode="singleTask"
android:configChanges="screenSize|orientation" />
What am I missing?