I'm now to android. And I'm having trouble in developing application in which I'm supposed to load data from a server and then populate list with this data. I used asyncTask to do so and I used onRetainNonConfigurationInstance() function to handle changing screen orientation while loading the data and it worked well.
The problem started when I wanted to handle changing the locale of my activity. As when I change the orientation the locale changes I've read these:-
How do I save an Android application's state?
and Activity restart on rotation Android
I want to make the layout to change from landscape to portrait So I didn't use
android:configChanges="locale|orientation"
I still can't solve it. I think that the system changes the language on its own so when I change the orientation even if i tried to set it using
Locale locale = new Locale("ar");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
I'll need to finish the activity and open it again which will make the user waits more also it'll make the application crash when the user try to change the orientation again.
I think that I may use onRetainNonConfigurationInstance() but i don't know how with these things I need to handle. So ANY Help will be appreciated.