Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android - How to detect application being activated

Tags:

java

android

When the app is launched, Application onCreate is called. How to detect when the app is brought to front from running in background?

like image 643
cubesoft Avatar asked Jun 12 '26 22:06

cubesoft


1 Answers

Look for onResume() method. Its is always called when your app comes foreground.

As per google docs:

The foreground lifetime of an activity happens between a call to onResume() until a corresponding call to onPause(). During this time the activity is in front of all other activities and interacting with the user. An activity can frequently go between the resumed and paused states -- for example when the device goes to sleep, when an activity result is delivered, when a new intent is delivered -- so the code in these methods should be fairly lightweight.

CODE SAMPLE:

@Override
public void onResume()
{
    super.onResume();
    Log.d("tag", "This screen is back");
}
like image 199
waqaslam Avatar answered Jun 15 '26 12:06

waqaslam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!