Android Lifecycle - ActivityManager kills process & # 8594; Exception when returning from background

I have a very boring problem. When my application goes to the background, sometimes the process is killed, as 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 try to return to the application, using the task switch (long press on the house), it tries to return to the last open action ... and it will work.

Why doesn't it open from scratch by opening Main, since the whole application was closed?

ERROR / InputDispatcher errors do not always appear.

UPDATE:

The problem is that ... the application is being restored, but the objects in it that were loaded (like a hash map) are not ... therefore, when I access them .... I have "problems" ...

UPDATE 2:

I managed to fix this problem by checking onCreate on BaseActivity (which is expandable by all others) if the application contains the data I need or if it is null (in this case it restarts the application).

Is there a more elegant solution, or at least a way to tell the device that if the application is killed, I want the application to restart?

These links helped to understand the problem ... and knowing that there is no clear answer to the question of how to store data from the application: How to declare global variables in Android?

UPDATE 3:

So, I asked a question about the correct storage of application data . This may help those who have the same question: Android: the best way to save data stored in a Singleton Class application

+6
source share
1 answer

As far as I understand, it returns because the user has not closed the application. Although: do you access the package data in this active action, which passed from the opening? If so, you can look at the save and restore functions of the package instance, which you can implement to decide that the application is returning to the foreground in an invalid state.

Edit for clarity: the application is restored to its previous state because it was killed by the OS due to low memory when it is in the background. When a task returns, it returns to this previous state, and invalid / nonexistent packet data may cause failure when this activity is resumed.

+3
source

Source: https://habr.com/ru/post/888438/


All Articles