Search code examples
androidandroid-activitybackandroid-homebutton

How-to Keep an Android Activity Running when hitting the back key


I have an activity that essentially launches a CountDownTimer. I need this to continue running while using other Android apps, such as Gmail, and media players etc.

When I hit the back button, my Activity seems to quit. What do I need to do to keep it running when the user clicks the back/home keys etc.


Solution

  • Activities are not supposed to be doing anything when they are not visible. They are basically UI components.

    You should be looking into services. These can run as a background process nd contain no UI.