Issue
I need a method to detect when my application is closing, so that I can tell a web-server to clear my session variable that it's storing. Is there any way to do that?
Solution
I'm assuming your application extends Activity.
You could use the onDestroy()
method:
From the docs :
onDestroy() is The final call you receive before your activity is destroyed. This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method.
Your code would look like this:
public class YourAppActivity extends Activity {
...
...
@Override
protected void onDestroy() {
super.onDestroy();
//clear your session variable.
//you may want to do this quick, and on another thread
//to prevent android from killing your app
}
}
Answered By - gideon
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.