malcoauri
malcoauri

Reputation: 12189

How to check if Android application goes to foreground?

Is it possible to check if the Android application goes to foreground? Maybe anything callback function? Any idea or suggestions is appreciated.

Upvotes: 1

Views: 133

Answers (3)

user3580042
user3580042

Reputation: 11

ActivityManager.getRunningTasks(1).get(0).yourActivity.getPackageName()

This method can get the foreground app package name.

you can use thread listen change.

Upvotes: 1

Daud Arfin
Daud Arfin

Reputation: 2499

As per android life cycle onResume and onStart will be called once your activity comes to foreground. For more details Android life cycle

Upvotes: 0

shweta_jain
shweta_jain

Reputation: 453

You can write code for callback activity in onRestart() Method.

Upvotes: 1

Related Questions