1

I need a way to check if a particular activity is visible or not. I cant use a simple boolean check in onStart and onStop, Since I need to access it in another process. I tried ActivityManager.getRunningTasks() but it gives me onCreate to onDestroy life cycle. I need onStart to onStop lifecyle.

Basically I want to know if the activity is between onStart and onStop.

bhkiran
  • 389
  • 1
  • 2
  • 11
  • http://stackoverflow.com/questions/18038399/how-to-check-if-activity-is-in-foreground-or-in-visible-background – Illegal Argument Jun 15 '14 at 16:58
  • Those method does not work if the boolean values are fetched from a service with different process ID. – bhkiran Jun 15 '14 at 17:02
  • as mentioned by many people in that post (most are from comments) there is no reliable way to determine that an activity is visible to the user you can try other ways but lifecycle callbacks like onpause and oncreate are not going to help you – Illegal Argument Jun 15 '14 at 17:05

1 Answers1

0

If your app uses API level 14 or newer, you can use the ActivityLifecycleCallbacks. Your should also read this:

Checking if an Android application is running in the background

Community
  • 1
  • 1
artkoenig
  • 7,117
  • 2
  • 40
  • 61