0

I'm troubling with android pending intent when notification comes.

My application's call stack is like A>B>C. So, B never can be created without A, and C never can be created without B.

Let's call the activity D which will be lunched from notification. then when user get a notification of D, I want it to be belows.

case1 A(MainActivity) is top activity, call stack should be A > D

case2 B(SomeActivity) is top activity, call stack should be A > B > C

case3 C(anotherActivity) is top activity, call stack should be A > B > C > D case4 D is top activity, destroy old D and create new D. case5 app is terminated, call stack should be A > D.

It looks like simple. But hard to make it right. My codes are

Intent intent = D.getIntent(context, model.getTitle(), model.getId(), Intent.FLAG_ACTIVITY_NEW_TASK);
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
    PendingIntent mBoxPendingIntent = PendingIntent.getActivity(context, (int) model.getId(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder b = new NotificationCompat.Builder(context)
            .setStyle(bigTextStyle)
            .setAutoCancel(true)
            .setTicker(tickerText)
            .setSmallIcon(smallIconRes)
            .setContentTitle(model.getTitle())
            .setContentText(model.getMessage())
            .setContentIntent(mBoxPendingIntent)
            .setWhen(when)
            .setLights(0xFFBD5475, 500, 3000);

now the problem is case 5. If on touch notification when application terminated, D is launched stand alone without A; And I can't know wether the device will has Activity A or not when user touch the notification. What am i supposed to do?

Jude KIM
  • 109
  • 1
  • 4
  • http://stackoverflow.com/questions/36912325/why-do-we-use-the-taskstackbuilder – X3Btel May 11 '17 at 09:04
  • You pretty much need to use https://developer.android.com/reference/android/support/v4/app/TaskStackBuilder.html to build your activity stack – X3Btel May 11 '17 at 09:05
  • Possible duplicate of [Why do we use the TaskStackBuilder?](http://stackoverflow.com/questions/36912325/why-do-we-use-the-taskstackbuilder) – X3Btel May 11 '17 at 09:05
  • @X3Btel Thank a lot. It works. But here's another problem. Do i have to create A again press back button on D? Here's the situation. Current call stack is A > D. Now get new notification which opens new D instead of old D. Press the notification and the call stack is still A > D. But when i go back, A is re-created. I want it to be just resume. Here's activity meta for A. `` – Jude KIM May 12 '17 at 00:32
  • And it is also doing wrong. when back stack is A>B>C. When I go back, It goes always A(re-create) and clear B,C. It supposed to be go back to C. Here's my codes. `PendingIntent pendingIntent = TaskStackBuilder.create(context) .addParentStack(A) .addNextIntent(A) .addNextIntent(D) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);` – Jude KIM May 12 '17 at 01:07

0 Answers0