The situation is this: ActivA (MainActivity) starts the service, after which I press the HOME button. Activation is in the onStop state, the service is running. When the service quits, it creates a notification, a standard NewMessageNotification created from the AndroidStudio template. Attachment to this notice:

notificationCompatBuilder.setContentIntent( PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT)) 

When you click on the notification, a new Activation opens (the onCreate event fires), naturally empty, without the results of the service. Then press the Back button, the Activation closes, and under it, a surprise! The old activit, worked onPostResume and loaded the data with the results of the service.

Question: How can I prescribe an intent in such a way that a new Activity is not created, but an old one wakes up?

  • one
    Try setting launch_mode = "singleTop" in the manifest of the activit - YuriiSPb
  • one
    Well, you yourself are creating a new mein of activity, so it appears, why don't you just add the results of the service operation to this intent and add flags to clear the stack of activations setFlags (Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); - Eugene Troyanskii

1 answer 1

In the manifest of the activation register launch_mode = "singleTop" You can also use the flag for Intent: intent.addFlags (Intent.FLAG_ACTIVITY_SINGLE_TOP) is similar to the singleTop value for launchMode.