I have a DialogFragment to display a list of options. So, I try to do several tests on my apps. I found a problem when changing phone system language in the phone settings while beforehand the DialogFragment is opening in my apps then go back into my apps. It caused a null pointer exception on the DialogFragment.
Basically, the repro is like this :
- Opening an activity
- The activity will open DialogFragment after some user actions
- The user exits the application and enters the phone setup
- The user changes the phone system language and then go back to the apps
- The DialogFragment still appears, but not in a proper format.
- The user presses the back button and the apps will crash automatically.
I've been trying several examples and solutions, but still the apps will crash after the repro stated above.
What should I do to tell the activity to close the DialogFragment when the user changes the phone system language? Do I need to put Flags? but How?
Here's the log :
java.lang.NullPointerException: Attempt to invoke interface method 'void com.example.MainDialogFragment$MainDialogListener.onDestroyMainDialogFragment()' on a null object reference
at com.example.MainDialogFragment.onDestroy(MainDialogFragment.java:152)
Before changing the phone system language :
After changing the phone system language and go back to the apps, the dialogfragment still appears, then the user presses the back button :
My Line 152 is :
@Override
public void onDestroy() {
myMainListener.onDestroyMainDialogFragment();
myMainListener = null;
super.onDestroy();
}
Here's my full code : https://codeshare.io/DZZRWO
Thanks in any advance