Android - How to activate the app

When the application is launched, the application is called onCreate

. How can I tell when an app is running in the background?

+3


source to share


2 answers


Look for a method onResume()

. It is always called when your application comes to the fore.

According to google docs :



The lifetime of a foreground object occurs between the call to onResume () until the corresponding call to onPause (). During this time, the activity is in front of all other activities and interacts with the User. Activity can often pass between resumed and suspended states - for example, when a device goes to sleep, when an activity is a result delivered, when a new intent is delivered, so the code in these methods should be light enough.

+3


source


You can override onResume ().

@Override
public void onResume()
{
    Log.d("tag", "This screen is back");
}

      



However, I would agree with the comment that you probably need to do more work on this to see how Android works.

+2


source







All Articles