i want add startup Activity for users to choose app language, how to make this activity to show only at startup and when the user chose the language the activity has to be gone forever?
-
Use `SharedPreference`. – Piyush Mar 01 '17 at 07:42
-
1Just launch this `Activity` and when the user chooses a required language use `Intent` to launch a new `Activity` and `finish()` to close it. – Denis Sologub Mar 01 '17 at 07:43
-
you need to store Language code or name some where like SharedPrefrence or SQLite so each time when your app open you first check about language status to be set or not . – Chetan Joshi Mar 01 '17 at 07:44
-
see link it could help you http://stackoverflow.com/questions/4636141/determine-if-android-app-is-the-first-time-used – Chetan Joshi Mar 01 '17 at 07:47
2 Answers
If I understand you correctly you wish to display that activity only when the user runs the app for the first time.
Well, here's what you can do:
1) Get a handle to a SharedPreference. This is to store if the user has already selected the language or not.
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
2) Create a SharedPreferences.Editor
SharedPreferences.Editor editor = sharedPref.edit();
3) Store the information in a key-value
editor.putBoolean("HAS_SELECTED_LANGUAGE", true);
4) Commit the change
editor.commit();
5) Check if 'HAS_SELECTED_LANGUAGE' is true in the onCreate() of the activity, if so move on to the next Activity/Fragment/etc
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
...
if (sharedPref.getBoolean("HAS_SELECTED_LANGUAGE", false)) {
//Replace with your action to perform if it is already selected
}
...
}
Also it would be recomended to allow the user to be able to come back and change the language from somewhere else if and when they require.
Hope this solve your problem.

- 415
- 3
- 11
You can specify resources tailored to the culture of the people who use your app. You can provide any resource type that is appropriate for the language and culture of your users. For example, the following screenshot shows an app displaying string and drawable resources in the device's default (en_US) locale and the Spanish (es_ES) locale.
<resources>
<string name="hello_world">Hello World!</string>
</resources>
<resources>
<string name="hello_world">¡Hola Mundo!</string>
</resources>
Read developer documentation as per your logic below.

- 610
- 9
- 15