0

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.

When i am in Activity2 ,i am Activity2 i am opening the settings and changing the language, then system reload the Activity2 . At this point in time i don't want to display activity2 ,i want to restart my application from starting.

Currently i have tried below logic in fragments which i have used in Activity2 to eliminate the crash.

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;
}
Krishna
  • 805
  • 8
  • 14
  • Possible duplicate of [How to refresh activity after changing language (Locale) inside application](http://stackoverflow.com/questions/8049207/how-to-refresh-activity-after-changing-language-locale-inside-application) – Selçuk Cihan Feb 23 '16 at 08:05

3 Answers3

0

Please try this. finish() both the activities after settings is change and start firstactivity intent. Thank you Hope it helps

Jagjit Singh
  • 1,909
  • 1
  • 14
  • 19
0

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

Coder29
  • 133
  • 1
  • 4
  • Yes agree with this. along with this i am doing below. protected void onCreate(Bundle savedInstanceState) { super.onCreate(null); handleLocalizationChanges(savedInstanceState); – Krishna Feb 26 '16 at 04:17
  • 1
    Ignore above . Below solved my problem. protected void onCreate(Bundle savedInstanceState) { super.onCreate(null); Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName() ); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); //Make sure to dismiss the alert dialogs if any } – Krishna Feb 26 '16 at 04:24
0

Use

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

See this solution here this may help you

Community
  • 1
  • 1
Abu Yousuf
  • 5,729
  • 3
  • 31
  • 50