سؤال

I want to log when the user opens and kills the app, and when it is put to the background. So far I have been trying with onStart/onStop/onPause/onResume/onDestroy etc, but this is only about the activity that I put this on, not the entire app. So when the user goes from the MainActivity to some other Activity inside the app, I don't need to know, but when he then goes out of the app, or even kills it, I would like to log that.

Any suggestions? (Did I write it down clear enough?)

هل كانت مفيدة؟

المحلول

onCreate()?

See the lifecycle diagram

Given your comments it seems you want the Application Lifecycle

Make a class that extends Application to make use of these (it will be instantiated automatically), just make sure you specify its name in your AndroidManifest.xml's application tag

Edit

I see your confusion, you want just oncreate/terminate here on the Application class

نصائح أخرى

I think what you are looking for, would be solved creating an AbstractActivity.

Implementing the log logic onCreate()when starts and onDestroy() when go out of the application.

Then all your activities could extends AbstractActivity so it would do the log stuff.

enter image description here

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top