I am developing a bilingual application. I want it to get fully restarted on language settings change. Here is the code I am using:
Intent restartIntent = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getBaseContext().getPackageName() );
PendingIntent intent = PendingIntent.getActivity(getBaseContext(), 0, restartIntent, Intent.FLAG_ACTIVITY_CLEAR_TOP);
AlarmManager manager = (AlarmManager) getBaseContext().getSystemService(Context.ALARM_SERVICE);
manager.set(AlarmManager.RTC, System.currentTimeMillis() + 1, intent);
System.exit(2);
This works fine except that after the app is restarted, I have two main activities (the old one still remains). How can I solve this issue?
Add finish(); to your current Activity
Intent restartIntent = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getBaseContext().getPackageName() );
PendingIntent intent = PendingIntent.getActivity(getBaseContext(), 0, restartIntent, Intent.FLAG_ACTIVITY_CLEAR_TOP);
AlarmManager manager = (AlarmManager) getBaseContext().getSystemService(Context.ALARM_SERVICE);
manager.set(AlarmManager.RTC, System.currentTimeMillis() + 1, intent);
finish();
System.exit(2);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.