Ex for better understanding:
My app is horoscope and my menu contains all the signs, if I selected "libra" every time my app opens, it will open in the libra fragment.
Thank you in advance
Ex for better understanding:
My app is horoscope and my menu contains all the signs, if I selected "libra" every time my app opens, it will open in the libra fragment.
Thank you in advance
I do something very little like what you are looking for, in my case it is automatic login.
After the user logs in to my app I save the user and the password and the next time he logs in I check if the file exists and I read the data and log in automatically, if all is correct, the user is directed to the main screen, otherwise it goes to the login screen.
In your case, you can save a configuration file containing the selected item, and when the app starts you go to this file and check which item was selected. And when the user makes a new selection, you change the file.
Put a variable that when you click on that item it takes such value, eg: clicked on item 1 the variable arrow 1, there you have the app save this data in localstorage, when it opens again load the data and so do what you want.
One option is to use Android's SharedPreferences . It is a mechanism for storing key-values
. The documentation has some examples of how to use this class.
When the user clicks on an item in the drawer you could save in a key what the name of the sign he has accessed:
Context context = getActivity();
SharedPreferences sharedPref = context.getSharedPreferences("nome_do_arquivo", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("ultimo_signo", "nome_do_signo_clicado");
editor.commit();
And when he opens the app again, you can retrieve this sign and do something with this information:
Context context = getActivity();
SharedPreferences sharedPref = context.getSharedPreferences("nome_do_arquivo", Context.MODE_PRIVATE);
String ultimoSigno = sharedPref.getString("ultimo_signo", "valor_padrao_caso_nao_exista_um_signo_ainda");