androidsharedpreferencesauth-token

how to store Authtoken in Shared preference and validate Auth token when call by remote server


I have an application which is connected to remote server, after registration from android side an Auth token is passed from remote server, where do I need to store that and validate in Android side.


Solution

  • Setting values in SharedPreference:--

    SharedPreferences prefs = getSharedPreferences("preference name", Context.MODE_PRIVATE); 
    SharedPreferences.Editor mEditor=prefs.edit();
    prefs.putString("key", value);
    prefs.commit();
    

    Retrieve data from SharedPreference:--

      SharedPreferences prefs = getSharedPreferences("preference name", Context.MODE_PRIVATE);  
        String restoredText = prefs.getString("key", null);