Android App Restarts upon Crash/force close

2019-01-16 03:58发布

My android app is getting restarted after force close, through my entire application which consist of 20 activities, I am relying on static data created on a main activity. So once the app is getting crashed all my static data is getting lost and when the app auto restarts practically it does not have any essential data to operate upon.

My question is, upon crash i want this things to happen

  1. If the app crashes, I don't want the app to restart rather I want all the stack/task related with this app to be wiped out of memory. A user can restart it from the beginning again
  2. If I can't prevent app from restart, at least I want to preserve essential data so that when the app restarts I can assign them back. Also when it restarts I want my app to start from the main activity.

I know when activity crashes android system will bring next activity in stack to foreground, and this is reason for my app producing redundant results. also i went through the android developers but only thing i got to know was setting up an attribute in Manifest android:finishOnTaskLaunch="true". But unfortunately this is of no help to me. I would appreciate your help on solving this issue, and also letting me know the cause and analysis.

7条回答
时光不老,我们不散
2楼-- · 2019-01-16 04:55

If the user is force stopping your app (from Settings > Apps > App Info, or from the recent apps list) or the operating system is stopping your app, then you can save whatever you need using onSaveInstanceState().

However, if your app is crashing, then there's not much you can do about it (apart from periodically saving important stuff to preferences/databases/etc.). It is probably better to focus on preventing crashes, rather than trying to handle crashes!

查看更多
登录 后发表回答