Note that there are some explanatory texts on larger screens.

plurals
  1. POHow should i do from notification back to activity without new intent
    text
    copied!<p>from Android Development, i implement a simple notification by the sample code, but in my app, i don't want to new intent and create the activity again, i just want to back to my last activity(it's a mediaplayer UI). if i use the sample code, it will create a new activity by</p> <pre><code>Intent resultIntent = new Intent(this, ResultActivity.class); </code></pre> <p>i comment relative code about new intent and got a notification, but didn't have idea how to back to my last activity... </p> <p>back to my app from long press home key and touch my app is OK. what i want is just like this behavior.</p> <p>bleow is the sample code from Android Development, i comment the new intent portion.</p> <pre><code>NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon) .setContentTitle("My notification") .setContentText("Hello World!"); /*Intent resultIntent = new Intent(this, ResultActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(ResultActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT ); mBuilder.setContentIntent(resultPendingIntent);*/ NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(mId, mBuilder.build()); </code></pre> <h1>[UPDATE]</h1> <p>i thought i need to set flag for intent and properity for activity. therefore, for the activity i want to back to i set</p> <pre><code>android:launchMode="singleInstance" </code></pre> <p>and because, i don't want a new activity from intent, i just want my last activity, so i add</p> <pre><code>Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY </code></pre> <p>from documentation i got that using <strong>Pendingintent.contentIntent</strong> it must include the <strong>FLAG_ACTIVITY_NEW_TASK</strong> flag and When using this flag, if a task is already running for the activity you are now starting, then a new activity will not be started; instead, the current task will simply be brought to the front of the screen with the state it was last in. so i also add </p> <pre><code>Intent.FLAG_ACTIVITY_NEW_TASK </code></pre> <p>but from logCat, i still saw that when i touch the notification for back to activity, the pendingintent still called onCreate() function rather than just show the last activity which still "alive".</p>
 

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