Android - How to restart system_process programmatically?
Thx. It does the magic! :)
PowerManager pm = (PowerManager) this.getApplicationContext().getSystemService(Context.POWER_SERVICE);
pm.reboot("bootloader");
Restarting Android app programmatically
If you just consider to switch to your starting Activity
, refer to Ricardo's answer. But this approach won't reset static context of your app and won't rebuild the Application
class, so the app won't be really restarted.
If you want to completely restart your app, I can advise more radical way, using PendingIntent
.
private void restartApp() {
Intent intent = new Intent(getApplicationContext(), YourStarterActivity.class);
int mPendingIntentId = MAGICAL_NUMBER;
PendingIntent mPendingIntent = PendingIntent.getActivity(getApplicationContext(), mPendingIntentId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
System.exit(0);
}
P.S. Tried your code in my project - works well with and without finish()
. So maybe you have something specific about your Activity or Fragment, you haven't written.
Related Topics
How to Get Background Color from Current Theme Programmatically
Designing Android Apps for Tablets
Change Button Text and Action - Android Development
How to Access an Existing Sqlite Database in Android
How to Prevent The Activity from Loading Twice on Pressing The Button
Signing My Android Application as System App
Android - Creating a New Activity in Eclipse
Android Build Gradle Is Too Slow (Dependency Resolution)
Crop Square Image to Circle - Programmatically
Combining Two Bitmap Image (Side by Side)
How to Kill All Running Applications in Android
What Would Happen If Android App Is Released with Debuggable On
Viewpager Update Fragment on Swipe
Android Listview with Checkbox Problem
How to Import Eclipse Library Project from Github to Android Studio Project