Can you track when an android application has been terminated?
Looked at android documentation and it appears that we don't have the ability to know when an app shuts down. Whether it was explicitly by the user or automatically by the operating system.
Below is the onTerminate()
documentation which is only available in the emulated scenario.
public void onTerminate()
Since: API Level 1
This method is for use in emulated开发者_StackOverflow中文版 process environments. It will never be called on a production Android device, where processes are removed by simply killing them; no user code (including this callback) is executed when doing so.
Does anyone have any other approaches to report back when the user closes the application?
We need to know from a pilot/usability standpoint if we need to incorporate additional functionality into our future production app.
Not sure whether this is going to help you...
In my app, I'm using Activity.onDestroy() to do the cleanup that I need. I have a couple of activities - and have onDestroy()
in each of them.
This is the closest I got to doing what I needed - and it actually works quite well.
Looked at android documentation and it appears that we don't have the ability to know when an app shuts down. Whether it was explicitly by the user or automatically by the operating system.
Users do not close applications on Android.
Does anyone have any other approaches to report back when the user closes the application.
Users do not close applications on Android.
Android, in this respect, behaves much like a Web browser. Users do not close Web applications in Web browsers. They might close the browser. They might close a tab. They might press the home button and navigate to a different site/app. They might choose a bookmark and navigate to a different site/app. They might drag a document into the browser and view it. They might double-click on a desktop icon and view it. And they might click some "logout" link in the currently-viewed Web site/app. Any of these cause the user to leave whatever Web site/app they are in, but none of them would be construed as "closing" the Web site/app in the same manner that clicking the close button on a desktop OS window might be construed as "closing" the desktop app.
As @Aleks G notes, there are various lifecycle methods you can override to find out what the user is doing with respect to an activity. onStop()
indicates something else took over foreground input and your current activity is no longer visible. onUserLeaveHint()
indicates that the user pressed HOME. And so on. But those are at the activity level, not the application level.
Make a BaseActivity extending Activity in your Application and extends this BaseActivity instead of Activity. In this BaseActivity override the onDestroy() method. Like
@Override
protected void onDestroy() {
super.onDestroy();
//Write the code that you want to do if the application terminates
}
精彩评论