How to restart Android app in Android 10 after few seconds

2020-05-23 android restart

I want to restart application after some seconds, following code worked in Android 8, but in Android 10 device nothing happens. Is ANY consideration is needed in Android 10? Here is the code worked in Android 8

Context mContext = getContext();
final int DELAY_I_WILL_BACK = 60;
. . .          
Intent mStartActivity = new Intent(mContext, MainActivity.class);
int mPendingIntentId = 123456;
PendingIntent mPendingIntent = PendingIntent.getActivity(mContext, mPendingIntentId, mStartActivity, 
       PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + DELAY_I_WILL_BACK*1000, mPendingIntent);
System.exit(0);

I tried mActivity.finishActivity(1); just before System.exit(0) but still does not working.

Answers

Related