Pergunta

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?

Nenhuma solução correta

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top