Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inducing ActivityManager to "No longer want" for testing

Tags:

android

I'm trying to test how my application handles getting destroyed by the Android ActivityManager (and later restarted by Alarm events). In other words, I want to force the message:

I/ActivityManager(  333): No longer want com.myname.myapp (pid 4444): hidden #22

Is there a way to reliably induce the ActivityManager to "No longer want" my application?


A few tricks I know for ending processes (however, the purpose of this question is to find something to induce the ActivityManager method of "No longer want").

  • Using Manage Applications, touch the button "Force Stop".
    The problem with this is it doesn't always seem to behave quite the same as the ActivityManager "No longer want" method.
  • Run many memory hogging applications.
    The problem with this is it's unreliable and time-consuming. Sometimes I can run lots of applications and I don't see a peep from ActivityManager.
  • OS API killBackgroundProcesses() .
    The problem with this is it was not clear if calling killBackgroundProcesses() explicitly would behave exactly the same as the ActivityManager "No longer want" method.
like image 545
JamesThomasMoon Avatar asked Oct 03 '11 19:10

JamesThomasMoon


1 Answers

In the newer version of Android there is a option of "Don't keep activities". After selecting that every activity gets destroyed as soon as the user leaves the Activity. For example we have activity A and B. Normal Flow

  • Activity A starts activity B

After selecting Don't keep activities

  • Activity A start activity B
  • B -> onCreate , A -> onDestroy (note that A doesn't call finish after starting activity B)
  • Pressing back button takes you back to Activity A
like image 64
Anirudha Agashe Avatar answered Nov 14 '22 23:11

Anirudha Agashe