Reputation: 1285
I am working on an android project. There is a MainActivity and a Service. When user press back key twice in a given time period within MainActivity, I use the following to finish the activity and stop the service.
finish();
int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);
When I press the app icon to restart the app, MainActivity appears and Service restarts. However, onCreate and onResume in the MainActivity is not called. The first call in the log is onAttach for fragments.
How could that be possible?
Upvotes: 0
Views: 65
Reputation: 13617
Check your Mainactivity onPause()
and onDestory()
If your onDestory()
called then you onCreate()
and onResume() Definitely Called
Note: onDestory is a risky one. If the app killed by Android for memory allocation most of the time onDestory won't get called.
Upvotes: 0
Reputation: 8106
You should not "kill" this by design.
Call
finish() and stopService() or stopSelf()
for your Service.
Killing the process may lead into unusual behaviour since the whole app gets restarted. It may be possible that even if the "App" is killed that the view is still in memory.
Upvotes: 1