S
S
Sergey Vodakov2016-08-18 17:41:05
Java
Sergey Vodakov, 2016-08-18 17:41:05

How to wake up an Activity?

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

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

When you click on the notification, a new Activity opens (the onCreate event fires), naturally empty, without the results of the service. Then I press the Back button, Activiti closes, and below it, surprise! The old activity worked onPostResume and loaded data with the results of the service.
Question: How can I register an intent in such a way that a new Activity is not created, but the old one wakes up?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
one pavel, 2016-08-18
@WaterSmith

<activity 
   android:name=".YourActivity"
   android:launchMode="singleTask"/>

E
Eugene, 2016-08-18
@evgstrannik

Pretty strange behavior... If I'm not confused, clicking on the notification should just "wake up" the old activity. Have you tested this on the same device/sdk version?
As a tip - try playing around with the activity flags in the manifest. But again, strange behavior...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question