简体   繁体   English

当用户处于二次活动状态并更改了Android中的语言时,如何重新启动应用程序

[英]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.

相关问题 手动更改权限后如何在android棉花糖中重新启动应用 - How to Restart the app in android marshmallow when permission changed manually 当用户在 Android 中关闭应用程序时,我如何重新启动应用程序 - how can i restart app when user close the app in Android 从“设置”更改“手机语言”时更改Android应用程序语言 - Change android app language when Phone language is changed from Settings 如何测试android应用语言是否已更改? - How to test the android app language changed or not? 使用 Android App Bundle 如何在系统语言更改时让系统下载新语言 - Using Android App Bundle how do i get the system to download a new language when the system language is changed 在Android中更改语言时如何更改操作栏语言 - How to change action bar language when language is changed in android Android 应用程序中的自动语言更改 - Automatic Language changed in Android App 更改手机语言时如何阻止用户界面更改 - How to stop user interface from changing when the language of phone is changed android 当用户更改手机语言时,我的android应用应如何更改其语言? - How should my android app change its language, when user changes mobile phone language? 如何在应用程序被杀死并再次打开时加载更改的语言 - How to load changed language when app is killed and open again
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM