@@ -2169,15 +2169,28 @@ static void applicationOpenedByNotification(@Nullable final String notificationI
2169
2169
sessionManager .onDirectInfluenceFromNotificationOpen (appEntryState , notificationId );
2170
2170
}
2171
2171
2172
- static boolean startOrResumeApp (Activity activity ) {
2172
+ // This opens the app in the same way an Android homescreen launcher does.
2173
+ // This means we expect the following behavior:
2174
+ // 1. Starts the Activity defined in the app's AndroidManifest.xml as "android.intent.action.MAIN"
2175
+ // 2. If the app is already running, instead the last activity will be resumed
2176
+ // 3. If the app is not running (due to being push out of memory), the last activity will be resumed
2177
+ // 4. If the app is no longer in the recent apps list, it is not resumed, same as #1 above.
2178
+ // - App is removed from the recent app's list if it is swiped away or "clear all" is pressed.
2179
+ static boolean startOrResumeApp (@ NonNull Activity activity ) {
2173
2180
Intent launchIntent = activity .getPackageManager ().getLaunchIntentForPackage (activity .getPackageName ());
2174
2181
logger .debug ("startOrResumeApp from context: " + activity + " isRoot: " + activity .isTaskRoot () + " with launchIntent: " + launchIntent );
2175
2182
2176
2183
// Not all apps have a launcher intent, such as one that only provides a homescreen widget
2177
2184
if (launchIntent == null )
2178
2185
return false ;
2179
2186
2187
+ // Removing package from the intent, this treats the app as if it was started externally.
2188
+ // This gives us the resume app behavior noted above.
2189
+ // Android 11 no longer requires nulling this out to get this behavior.
2190
+ launchIntent .setPackage (null );
2191
+
2180
2192
activity .startActivity (launchIntent );
2193
+
2181
2194
return true ;
2182
2195
}
2183
2196
0 commit comments