私は自分自身を困惑させる非常に良い質問です。
アプリを強制終了してから電話を再起動するまでの違いは何ですか?
ユーザーが手動でアプリを強制終了したり、他の20個のアプリを開いた場合は、最初からアプリを開始したいと考えています。 携帯電話の再起動後にAndroidが状態を復元しない理由を教えてください。
また、(システムによって)アプリが強制終了されると、アクティビティの再起動時にグローバル変数がnullに変わります。 この種のJavaの概念が壊れています。アプリケーションに何らかの状態があり、アプリケーションがその状態を消去した場合、アプリケーションを再起動すると思います。
私が提案する解決策:
1. Handle the case of a state problem: Initiate a simple state (new Object()) as a global variable. For each Activity, in the methods onCreate/Start/Resume check that the state is null. If it's null launch the first activity with 'Intent.FLAG_ACTIVITY_CLEAR_TOP' - as if the application is relaunched.
2. Try not to use global variables - Always put data in the intent.
3. Lazy load global variables - If you do want to use global data, don't count on one time initialization. Lazy load them 'if (A.MY_DATA == null) {A.MY_DATA = new ...}' - Don't forget to do it in the background if it will take a long time (AsyncTask). Loading partial state needs to be done carefully because it may not comply to other loaded state objects.
最初のポイントのマイナス面は、状態に問題の取り扱いは(AOPがまだのAndroidに実装されていない)すべての活動に行われる必要があるということです。
希望しました。
+1良い質問です。スタックトレースを投稿することもできますか? –