This is a follow up question to this question:
Force application to restart on first activity
I am trying to restart my application from a fragment like that:
As the accepted answer doesn't seem to work on Android Q anymore due to the new background launch limitations, let me add my own solution:
startActivity(
Intent(applicationContext, MainActivity::class.java)
)
System.exit(0)
Although it looks strange, it works very reliably for me, as the intent takes longer to fire than the system exit does. Plus, it is fired from the main thread, so Android Q won't complain.
Please refer below code
Intent intent = new Intent(this, YourHomeActivity.class);
this.startActivity(intent);
this.finishAffinity();
It is starting your home activity and dismiss all other activities. It looks like a restart to users, but the process is the same.
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage( getBaseContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(i);
You can refer to previous discussion (click here)