androidandroid-activityonpause

How can I manually trigger my Android onPause() method to test it?


I would like to manually test that the Android app I am writing works correctly when paused. What can I do through the Android GUI to cause the onPause() method to be called without causing onStop() to also be called?

I've tried pulling down the notification bar and receiving a phone call, but neither causes onPause() to be called.

I would like to find a non-programatic solution that works for multiple versions of Android through the GUI, with or without phones, because I am teaching a class full of students using different devices.

Note that I am not asking how to tell if my onPause() method is called. I am asking what I can to do cause it to be called, without modifying my application.


Solution

  • I found a solution. I got the idea from a picture in the book Head-First Android Development.

    1. Install Any Do.
    2. Create a task.
    3. Set an alarm for a few minutes in the future.
    4. Start the app under test.
    5. When the alert comes up, my app gets partly obscured, and its onPause() method gets called. If I click on the Dismiss icon, my app resumes without its onStop() method having been called.

    Picture showing app partly obscured by Any Do alert