3

I have an Android app that logs in to a server, gets a session ID and uses it for as long as the app is running. The session ID is stored in the SharedPeferences .

For some reason, on one device (an old Samsung Galaxy S), sometimes when the application wakes up, the session ID is gone - it can't be retrieved from the SharedPreferences, and instead - null is returned. This happens probably after some heavy use of the phone, requiring Android to free up memory resources. Note that the application is still alive, it isn't restarted from scratch - my activity just gets onResume called.

I'd be really happy if I could reproduce this behavior on the emulator. Is there a way to nudge the emulator into doing the same thing?

4

1 に答える 1

5

そのような状況であなたのアクティビティも onCreate になっていないとしたら、私は驚かれることでしょう。エミュレータでこの種のものをテストするための戦略は、アプリケーション内のすべてのアクティビティを一時停止してから、adb を使用してプロセスを強制終了することです。これは基本的に、リソースが不足したときにフレームワークが行うことです。アクティビティを再開すると、新しいプロセスが作成され、一時停止時に保存された状態からアクティビティを再初期化しようとします。

于 2013-04-14T07:41:32.360 に答える