How to reset/restart the app when onTrimMemory() method is called?

917 Views Asked by At

Currently I am handling onTrimMethod(int level) in my app with ComponentCallbacks2.TRIM_MEMORY_COMPLETE and ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL. I get this callback easily with low end devices when my app is running in background and simultaneously I am playing games.

In that I put Runtime.getRuntime().exit(0); to kill the app in background only so that when user taps on app (running in background), app will restart from launcher activity. I don't know it kills the app or not but when I open the app, first it shows dialog with "Unfortunately, app has stopped" and app does not restarts.

If I start the activity from this method, it will launch the application and bring it to foreground without any user interaction.

I tried some other ways too to kill the app. They are System.exit(0); and android.os.Process.killProcess(android.os.Process.myPid()); but none of them are solving my problem.

So, what to write in onTrimMethod() or how to handle in other way so that when user opens the application (brings to foreground from background) it will start from the first activity?

0

There are 0 best solutions below