开发者

On resart activity how to clear stored variables?

When I restart an Activity u开发者_JAVA百科sing

Intent intent = new android.content.Intent();
intent.setClass(this, this.getClass()); 
this.startActivity(intent);

A lot of the state is remembered, but I want to clear it all (its a rare exception handler that I am using to try to clear all).


What you'd have to do is kill the activity in the onPause() method (by calling finish()) . What happens is that when you call your intent and your activity was already created but it's sleeping, it doesn't call its onCreate(), it just calls onResume() and all the state would be there.

This may have other consequences, i.e. if the user is working on your app an a text or a phone call arrives your activity would be killed, losing all the state.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜