문제

I'm having a very boring problem. When my app goes to background, sometimes the process is killed as the LogCat shows:

INFO/ActivityManager(187): Low Memory: No more background processes.
INFO/ActivityManager(187): Process com.app.myapp (pid 20681) has died.
INFO/WindowManager(187): WIN DEATH: Window{40592708 com.app.myapp/app.myapp.dashboard.Dashboard paused=false}
ERROR/InputDispatcher(187): channel '408b1d40 app.myapp/app.myapp.menus.products.Promotions (server)' ~ Consumer closed input channel or an error occurred.  events=0x8
ERROR/InputDispatcher(187): channel '408b1d40 app.myapp/app.myapp.menus.products.Promotions (server)' ~ Channel is unrecoverably broken and will be disposed!
INFO/WindowManager(187): WIN DEATH: Window{408b1d40 app.myapp/app.myapp.menus.products.Promotions paused=false}
INFO/ActivityManager(187): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10100000 cmp=app.myapp/.Main } from pid 187
INFO/ActivityManager(187): Start proc app.myapp for activity app.myapp/.menus.products.Promotions: pid=20721 uid=10062 gids={3003, 1015}

When i then try to return to the app, via task switcher (long press home) it tries to return to the last opened activity... and crashes.

Why doesn't it open from scratch, opening Main as the whole app was closed?

The ERROR/InputDispatcher erros do not always appear.

UPDATE:

The problem is... the Application is restored, but the objects in it that were downloaded (as a hashmap) aren't... so when i access them.... i have "problems"...

UPDATE 2:

I've manage to fix the problem by verifing on onCreate on BaseActivity (that is extended by every other) if the Application contains the data I need or if it's null (in this case it restarts the app).

Is there a more elegant solution, or at least a way to say to the device that if the application is killed, i want the application to be restarted?

This links helped understand the problem... and knowing there is no clear answer for how to store the data from Application: How to declare global variables in Android?

UPDATE 3:

So I asked a question specifically of how to save Application data correctly. This may help those with the same question: Android: Best way to save data stored in Application Singleton Class

도움이 되었습니까?

해결책

As far as I ubderstand it goes back because the user didn't close the application. A though: are you accessing bundle data in that activity that's passed from the opening activity? If so you may want to look into the bundle instance saving and restoration functions that you can implement to solve the app coming back into the foreground in am invalid state.

Edit for clarity: the application is restored to its previous state because it was killed by the OS due to low memory while it's in the background. Upon task switching back it's restored to that previous state and invalid / non-existent bundle data may be causing the crash when that activity is resumed.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top