views:

30

answers:

1

When I restart an Activity using

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).

A: 

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.

Ricardo Villamil
You could implement all your initializing in onResume()
Falmarri
This answer is exactly what I wanted to know, thank you Ricardo Villamil, I will put finish() in onPause() and then get a new set of variables when the App is restarted (in my case I need this behaviour)
Droid