我正在开发双语应用程序。我希望它在语言设置更改时完全重新启动。这是我正在使用的代码:
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);
正常运行,除了重新启动应用程序后,我有两个主要活动(旧的活动仍然存在)。我该如何解决这个问题?
最佳答案
添加finish();您当前的活动
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);