kumar piyush
kumar piyush

Reputation: 173

Restarting Android Application

At the end of my application , i have a button to restart the application..

What is the way to restart an application in the onClick Listener of a button??

I tried doing it by creating an intent with "com.android.action.main"

But it doesnot work?

Upvotes: 0

Views: 601

Answers (1)

Vipul
Vipul

Reputation: 28093

Put following code in your onClick

Intent i = getBaseContext().getPackageManager()
             .getLaunchIntentForPackage( getBaseContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

Upvotes: 4

Related Questions