Reputation: 23596
In My Application i am going to give the value to the Sharedpreference and also fetch it and do some operation.
If i'm on that activity and check for the shared value it is not going to change. But if once i close the application and then if i reopen that application and see the shared preference value then it shows that change values.
i am going to store the value as like:
myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
TWITTER_NAME = myPrefs.getString("username", "");
TWITTER_PASSWORD = myPrefs.getString("password", "");
SIGNIN = myPrefs.getBoolean("signin", false);
System.out.println("THE VALUSE OF username is: "+TWITTER_NAME);
System.out.println("THE VALUSE OF password is: "+TWITTER_PASSWORD);
System.out.println("THE VALUSE OF signin is: "+SIGNIN);
and fetching the value at the same activity like:
myPrefs = TWSBIDrawMainActivity.this.getSharedPreferences("myPrefs",MODE_WORLD_WRITEABLE);
prefsEditor = myPrefs.edit();
prefsEditor.putString("username", USERNAME);
prefsEditor.commit();
prefsEditor = myPrefs.edit();
prefsEditor.putString("password", PASSWORD);
prefsEditor.commit();
So is it possible to take effect the value of the shared preference at the same activity ?
Upvotes: 0
Views: 518
Reputation: 8612
And what do you want to do with changed shared prefs? As I understand you want user to login, so if there is correct prefs you call login(String, String)
, if there is no correct prefs you show input for login and pass, and login button. On button click you can save prefs and call the same login(String, String)
as in first case.
Upvotes: 1