Mushtaq Ahmed
Mushtaq Ahmed

Reputation: 3

How can i Reset my activity with the press of a button

I want to reset my activity, there are few functions and methods being performed in my class and i want that when i press the button everything resets and comes to a start just like at first how the activity gets started.

Upvotes: 0

Views: 101

Answers (5)

KishuDroid
KishuDroid

Reputation: 5451

Try this :

Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
overridePendingTransition(0, 0);
startActivity(intent);

Upvotes: 0

Chamatake-san
Chamatake-san

Reputation: 551

Perhaps easier is this...

this.recreate();

there's some restriction about API less than 11 I think - you'd want to look that up if your app supports API less than 11.

Upvotes: 0

Sandeep Singh
Sandeep Singh

Reputation: 1127

Try this..

    Intent intent = new Intent(this,yourActivity.class);

    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);

Upvotes: 3

Klawikowski
Klawikowski

Reputation: 615

Easiest way:

Intent intent = getIntent();
finish();
startActivity(intent);

Upvotes: 0

Amsheer
Amsheer

Reputation: 7131

Try this:

Intent i =  new Intent(YourActivity.this, YourActivity.class);
                    startActivity(i);
                    finish();

Upvotes: 1

Related Questions