Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application not open main activity when it was killed after pressing home button in android

Tags:

android

In my Application, activity A is launcher activity, from A it called B and from B it called C, I have such more than 5 activities. In C when I press home button, and again open my app it open C, that is fine in my case. But after pressing home button in C, when it idle for some time and application is killed, after that when I open my app it opens C. But I want to open main launcher activity that time. How can I do this?

A > B > C > HOME button > idle for some time > application killed > open app > C.

In this case I want to open main activity A instead of C.

like image 777
Mihir Shah Avatar asked Sep 11 '12 05:09

Mihir Shah


People also ask

What happens to activity when home button is pressed?

When Home button is pressed, onStop method is called in your activity. So what you may do is to add finish(); in onStop method to destroy your activity. Eventually onDestroy method will be raised to confirm that your activity is finished.

Does Pressing Home button close App?

Pressing the Home switches you from the app to the home screen, whilst leaving your app running in the background.

How do I stop an android application from closing?

In android, by pressing a back button or home button. So put an event key listener for back & home button and terminate the service.

What is process death in Android?

ViewModels are automatically destroyed by the system when your user backs out of your activity or fragment or if you call finish() , which means the state will be cleared as the user expects in these scenarios. Unlike saved instance state, ViewModels are destroyed during a system-initiated process death.


1 Answers

You will need to detect that Android has killed your process and then after that the user has returned to the app (causing Android to create a new process). I've described how to do this in numerous answers:

https://stackoverflow.com/a/29802601/769265

https://stackoverflow.com/a/27276077/769265

https://stackoverflow.com/a/11249090/769265

like image 198
David Wasser Avatar answered Sep 18 '22 13:09

David Wasser