简体   繁体   中英

Continuing the same activity when user clicks on Notification

i am making an application in which Broadcast listener is starting an activity and notification is displayed. when a user clicks on home button it goes to the home screen. But if user clicks on Notification icon then activity state is lost :( .

Please help me how to continue with my activity when user clicks on notification.

Try this:

Intent resultIntent = this.getIntent();

It gets the started intent from main activity. Worked for me.

I don't display a notification if the application that is doing the notifying is in the foreground; I just update the UI of the activity and let it be self-evident.

Try this 

Intent.FLAG_ACTIVITY_TASK_ON_HOME

I suggest using an alert dialog for notifications link here. This will keep your notification on the same screen and in the same activity.

If you want to keep any information when you press home you may use android storage for that and here is the link for that. Storage will be able to hold data that you need from other activity classes.

I hope this helps you.

When building your Intent for the PendingIntent you send with the notification, add the flag Intent.FLAG_ACTIVITY_NEW_TASK .

If the activity is already on the history stack, it will be resumed and a call to onNewIntent() will be triggered. If it's not, the activity will be started with a blank slate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM