event when app is started, stopped and paused

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.

在这里输入图像描述

链接地址: http://www.djcxy.com/p/90806.html

上一篇: 在哪种情况下应该重写onDestroy()?

下一篇: 当应用程序启动,停止和暂停时发生的事件