Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid:Notification starts new activity instead of resuming old one if originally activity is not started from launcher
    primarykey
    data
    text
    <p>I have spent a week to find a solution but with no success, so I need a help.</p> <p>When my application goes to background then notification appears and displays status of activity.</p> <p>It works perfectly if the application is started from launcher (with <code>action = android.intent.action.MAIN</code> and <code>category = android.intent.category.LAUNCHER</code>). But if the application is started f.e. from the gallery using action <code>android.intent.action.SEND</code> or <code>android.intent.action.SEND_MULTIPLE</code> and category <code>android.intent.category.DEFAULT</code>, then notification starts new activity instead of resuming existing one.</p> <p>The code for notification:</p> <pre><code>String ns = Context.NOTIFICATION_SERVICE; NotificationManager notificationManager = (NotificationManager) getSystemService(ns); int icon = R.drawable.icon; Notification notification = new Notification(icon, null, 0); notification.flags |= Notification.FLAG_ONGOING_EVENT|Notification.FLAG_AUTO_CANCEL|Notification.FLAG_ONLY_ALERT_ONCE; Context context = this.getApplicationContext(); CharSequence contentTitle = "XXX"; CharSequence contentText = "XXX"; Intent notificationIntent = new Intent(context, MyClass.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent activityIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, activityIntent); notificationManager.notify(NOTIFICATION_ID, notification); </code></pre> <p>In other words, I have an application "My Application" with activity "My Activity". If "My Activity" is started on the top of gallery and creates notification, then after pressing the notification "My application" is started instead of resuming the gallery with "My activity".</p> <p>Do you have any idea how to heal it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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