Android App Restart - Not Working for Android 11

271 views Asked by At

To Restart the App : done as below :

   fun restartApp(context: Context) {
    try {
        val mStartActivity = Intent(context, SplashActivity::class.java)
        val mPendingIntentId = 123456
        val mPendingIntent: PendingIntent = PendingIntent.getActivity(context, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT)
        val mgr: AlarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
        mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 500, mPendingIntent)
        System.exit(0)
    } catch (e: java.lang.Exception) {
        e.printStackTrace()
    }
}

Then Tried as below :

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

But, no success.

I am updating the Firmware in BLE device and after successful write I require to restart the App completely. Implemented above two approaches but with no success.

I want to clear all assigned values and have to restart the app i.e. not just starting new activity.

How can I achieve this? Thanks.

NOTE : There are many solutions for this questions but it might be specific for Android 11.

0

There are 0 answers