The application restarts if you select the application from the latest applications only if the activity starts with a notification

My application has a stack of actions as shown below

  • A: boot activity
  • B: core business
  • C: detailed activity

and the manifest is as follows

<activity A>
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>
<activity B android:launchMode="singleTask"/>
<activity C/>

when I start the application from launch, it acts like A → B → C. press the "Home" button in step C and call it from the list of recent applications (click "Home"), C. will appear. This is normal.

but when I start the application from Notification, since I don’t want to show the loading screen, activity B starts. so the user can navigate B → C.

"" C , B . , C .

, . , , - , , .

. Intent.FLAG_ACTIVITY_CLEAR_TOP B.

Notification notice = new Notification(R.drawable.icon_notification, context.getString(R.string.app_name), System.currentTimeMillis());

Intent intent = new Intent(context, B.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtras(i);

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

, , B. , C, B.

.: (

UPDATE

, .

  • D . B ( ).
  • D
  • D B
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY)  != 0 ) {
  i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_NEW_TASK);
} else {
  i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}

D

   <activity
            android:name="D"
            android:clearTaskOnLaunch="true"
            android:excludeFromRecents="true"
            android:exported="false"
            android:launchMode="singleInstance"
            android:noHistory="true"
            android:taskAffinity="xxx"
            android:theme="@android:style/Theme.NoDisplay">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
        </intent-filter>
    </activity>
+5
2

, - , , , . :

(getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0

, , .

+8

, , - Intent.FLAG_ACTIVITY_NEW_TASK. A , B . , , - , .

+1

All Articles