Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to force app out of memory in Android emulator?

I've implemented application state saving/loading in onSave/RestoreInstanceState and onCreate in one of my android app's activities. Is there any way to force the emulator to remove my app from memory so that onRestoreInstanceState is called?

Currently it looks like my app just stays in memory (for a time longer than I am willing to wait anyway). When I hit the "home" button when my activity is active I get the following method calls:

  • onSaveInstanceState
  • onStop

When I reactivate my app, all I get is

  • onRestart

Is there any way in the emulator to force my app to be mothballed so that onRestoreInstanceState and/or onCreate are called again?

like image 554
Mike Marshall Avatar asked Nov 03 '11 20:11

Mike Marshall


People also ask

How do I simulate out of memory on Android?

Create a loop, that allocates objects to memory. You can just "new" up a bunch of objects in a loop, and run it that way. If you allocate enough Strings, or int objects into a single array, this will run OOM eventually (this is also a good way to gradually build to an OOM condition).

What is the onTrimMemory () method?

onTrimMemory. Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process. This will happen for example when it goes in the background and there is not enough memory to keep as many background processes running as desired.

Is it possible to run an application in the private memory space of another application?

It is possible. Just use the Windows API functions WriteProcessMemory/ReadProcessMemory . Pass in the handle of the process and the pointer to the data.

What is PSS memory in Android?

When inspecting your app's heap, Android computes a value called the Proportional Set Size (PSS), which accounts for both dirty and clean pages that are shared with other processes—but only in an amount that's proportional to how many apps share that RAM.


1 Answers

Use the DevTools app ("Immediately destroy activities").

like image 136
Joe Avatar answered Oct 03 '22 06:10

Joe