开发者

Activity order from notification

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 generat开发者_高级运维ing notification.

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

What is other way to solve this?


try after adding these flags to your intent:

notificationIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);


@ 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜