简体   繁体   中英

Android: simulate long running time

I guess everybody experienced his app work great when you try it for a quick 30 minutes. But when an app sits in the background of the device for a day or so, you get your NullPointerExceptions and things don't work as expected because the Garbage Collector stole your stuff. Is there any way to simulate an app running for a long time in the background?

Settings -> Developer options -> Background process limit -> At most 1 process.

Don't forget to set it back when you're done having fun. Cheers.

You don't really need to wait any specific amount of time. You just have to do something that eats memory. This could be a special app you create for the task, but you don't really need to.

In my experience, most games seem to work. Games with a lot of graphics tend to work best, since they're using up a lot of memory for textures, etc. Angry Birds or Candy Crush will work also, even though there aren't advanced graphics or heavy processing(probably for the same reason they chew through the battery). Normally, after playing just a level or so, you can return to your Activity and see what got lost.

Optimally, you'll be using smart ways to persist/initialize your data, so this shouldn't be that much of a problem, but occasionally you(or a user) run into something unexpected, and this can help you track it down.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM