Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What you need is just a simple Activity that does nothing. Here is an example:</p> <pre><code>public class NotificationActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Now finish, which will drop the user in to the activity that was at the top // of the task stack finish(); } } </code></pre> <p>Set up your notification to start this activity. Make sure that in the manifest the task affinity of this activity is the same as the task affinity of the other activities in your application (by default it is, if you haven't explicitly set <strong>android:taskAffinity</strong>).</p> <p>When the user selects this notification, if your application is running, then the NotificationActivity will be started <strong>on top</strong> of the topmost activity in your application's task and that task will be brought to the foreground. When the NotificationActivity finishes, it will simply return the user to the topmost activity in your application (ie: wherever the user left it when it went into the background).</p> <p>This won't work if your application isn't already running. However, you have 2 options to deal with that:</p> <ol> <li><p>Make sure the notification isn't present in the notification bar when your application is not running.</p></li> <li><p>In the onCreate() method of the NotificationActivity, check if your application is running, and if it isn't running call startActivity() and launch your application. If you do this, be sure to set the flag <strong>Intent.FLAG_ACTIVITY_NEW_TASK</strong> when starting the application so that the root activity of the task is not NotificationActivity.</p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload