Start new activity with notifications in android

I want to start Activity A from the status bar notification. When activity A is already ahead, I want to end this and a new initial activity A. How can I do this?

+4
source share
2 answers

Review the documentation for creating status notifications. This definitely covers the launch and activity from notification using Intent and PendingIntent.

http://developer.android.com/guide/topics/ui/notifiers/notifications.html

As for the activity is already running, finish it and run it again ... I'm not sure if this can be done easily, depending on what you really want. You can do something with the launch mode activity parameter in the manifest:

http://developer.android.com/guide/topics/manifest/activity-element.html#lmode

And then respond to your activity (with the probability of onNewIntent ()) and "reset" programmatically. Maybe something like this:

Android will restart my activity

+1
source

Do you mean the re-start of action A? While the most common approach is to re-launch a new Intent with the same class, I think it uses too much memory. I would prefer to create an init method that should be called from onCreate And when you want to restart your activity. Example:

public void onCreate(Bundle si){ // Call super and set your layout... init(); } /** * This method should be called whenever you want to restart your activity. The * biggest advantage is you already have your layout (setContentView() method) */ private void relaunchActivityA(){ // Clean or save anything you need to clean or save init(); } private void init(){ // Init your variables, threads, and so on } 

If you wrote: โ€œFinish this, then start Activity Aโ€ instead of โ€œActivity Bโ€, and then immediately after startActivity () - into the A-call โ€œfinishโ€ action. Example:

 // This is inside Activity A Intent i = new Intent(this, ActivityB.class); startActivity(); finish(); // This will be called right after 'Activity B' finishes 
+1
source

All Articles