[英]How to restart the app when user is in secound actvity and changed language in android
I have 2 activities Activity1,Activity2 , when i open my application Activity1 will get displayed from there i will navigate to Activity2 and this time Activity1 is in background. 我有2个活动Activity1,Activity2,当我打开我的应用程序时,Activity1将在那里显示,我将导航至Activity2,这一次Activity1在后台。
When i am in Activity2 ,i am Activity2 i am opening the settings and changing the language, then system reload the Activity2 . 当我处于Activity2中时,我是Activity2我正在打开设置并更改语言,然后系统重新加载Activity2。 At this point in time i don't want to display activity2 ,i want to restart my application from starting.
在这一点上,我不想显示activity2,我想从启动重新启动我的应用程序。
Currently i have tried below logic in fragments which i have used in Activity2 to eliminate the crash. 目前,我已经在Activity2中使用的片段中尝试了以下逻辑以消除崩溃。
Fragments: 片段:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(
R.layout.point_selection_list_fragment, container, false);
if (savedInstanceState != null) {
Utils.removeFragment(this);
return view;
}
return view;
}
Please try this. 请尝试这个。 finish() both the activities after settings is change and start firstactivity intent.
finish()既可以更改设置后的活动,也可以启动firstactivity意图。 Thank you Hope it helps
谢谢希望对您有帮助
Hope it will help. 希望它会有所帮助。
Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
Only problem with this it will not restart the application, only re-create the classes. 唯一的问题是它不会重新启动应用程序,只会重新创建类。 Thus, any static variables within the classes will retain values from previous runs
因此,类中的任何静态变量都将保留先前运行的值
Use 采用
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
See this solution here this may help you 在这里查看此解决方案可能对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.