In the default android launcher, pressing home while in another activity will start the launcher. Pressing home again while in the launcher will reset to the default home screen page. I don't understand how this can be done. Android sends the same intent whether the launcher is in the foreground or not. Home key also cannot be intercepted by user apps.
Is there a way to achieve this?
to be more specific, do
Correct.
Correct.
If a call to
startActivity()
will result in theIntent
being delivered to an existing instance of the activity, a new instance is not created (by definition) and the existing instance is called withonNewIntent()
instead ofonCreate()
.In the case of a home screen, typically the activity that truly is the home screen will use
android:launchMode="singleTask"
orandroid:launchMode="singleInstance"
in the manifest, such as:(from an old launcher in the AOSP)
Then, the activity can implement
onNewIntent()
to do something. In the case of the aforementioned old launcher, itsonNewIntent()
includes:This, presumably, animates the UI back to the default screen if the user is presently viewing some other screen within the set of screens managed by the home screen activity.
Another approach to trigger
onNewIntent()
, instead of usingandroid:launchMode
, is to do it selectively when you callstartActivity()
, by including appropriate flags in theIntent
, such asFLAG_ACTIVITY_REORDER_TO_FRONT
.