0

I have an app that shall be extended with an app tracking code that should track the following events: app started, closed, foreground and background. My application has two activities.

For app started i use app.onCreate(). For foreground and background: onResume and onPause in each activity.

So my questsions are:

  • How do i detect when the application is completely gone? Something like onTerminate()?
  • When switching from the first activity to the second, i get a1.onPause() and then a2.onResume() and thus the events background followed by foreground. In that case i don't want those events. How do i know in onPause or onStop that i am staying in my app and only switching activities?

What i want is: App starts with a1 -> app started and app foreground event then switch to a2 -> nothing, press home -> background. When the app gets killed -> closed

At least i think i want that, or should one not use such a linear approach because of androids specific application and activity lifecycle and do something else?

spatialist
  • 3,206
  • 4
  • 22
  • 17
  • Hi, check out these links http://stackoverflow.com/questions/5836843/android-detecting-if-an-application-entered-the-background http://stackoverflow.com/questions/3183932/androidhow-to-check-if-application-is-running-in-background http://stackoverflow.com/questions/1068121/android-how-to-release-resources-when-the-application-terminates – Vishwanath.M Jul 23 '12 at 08:59
  • if you are using API level 14+ you can look at http://developer.android.com/reference/android/app/Application.ActivityLifecycleCallbacks.html – dsafcdsge4rfdse Jul 23 '12 at 09:07

1 Answers1

0

How do i know in onPause or onStop that i am staying in my app and only switching activities

I'm afraid you can't detect this only using callbacks.

How do i detect when the application is completely gone? Something like onTerminate()?

AFAIK framework doesn't provide such callbacks for you.