2

I have a question regarding Android Notification and activity order.

I have following scenario:

I have Activity_Main as my first activity, which performs some task. When BACK button is pressed It generates notification. Activity_Main has following calls (onKeyDown(), OnPause(), OnStop(), OnDestroy()). When user clicks the notification icon Activity_Main is started and call sequence is (OnCreate(), OnResume()). Which is fine.

Now Activity_Main contains button which starts Activity_Second using StartActivityForResult() api and also generates notification of task progress, function calls are (onSaveInstance(), OnPause(), OnStop()). If user presses back button on Activity_Second by setResult(result), everything works fine. But if the user selects the Notification icon (activity_seconds is visible) then new instance on Activity_main (onCreate(), OnResume()) started. What i want is Activity_Second should close it and (onResume() of Activity_Main) should be called. Right now Activity_Main(2nd instance), Activity_second, Activity_Main(1st instance) is on activity stack.

I have following flags set while generating notification.

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);

What is other way to solve this?

JRC
  • 808
  • 1
  • 11
  • 26

2 Answers2

1

try after adding these flags to your intent:

notificationIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Vineet Shukla
  • 23,865
  • 10
  • 55
  • 63
1

@ vineet, it didnt help.

Intent notificationIntent = new Intent(this,Activity_Main.class);

and

<activity ....android:launchMode="singleTask" >

togather helped me to solve this... from this link

Community
  • 1
  • 1
JRC
  • 808
  • 1
  • 11
  • 26