I have a RESTful web-service
, I am retrieving a data to android device
So here My ip address
/Doamin
name may change like..
192.168.0.1
or1-255
etc or It may be www.stackexchange.com
or www.stackoverflow.com
Like my data will be stored in 192.168.0.1/rst/api/login
or www.stackoverflow.com/rest/api/sitemview
So to over come this I want to use domain name as One time when i install application
in my application I have other pages like Login
,display list-view
, Single ItemView
.
So this domain name should stored in device and pass to other activities every time when I use.
I used shared preferences like
public static void savePreferences(Context ctx, String key, String value) {
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(ctx);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(key, value);
editor.commit();
}
so when they load
public static Object loadSavedPreferences(Context ctx, String key) {
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(ctx);
return sharedPreferences.getString(key, "");
}
So here My problem is that This one time value is not permanent when ever I force close or Restart devise that passing value is not working
Any suggetion
If your domain name fixed, use below code.
Access it in each activity with