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