sharedpreferences - Android Preferences onBackButton -


i'm saving users login information sharedpreferences, has configure login data once.

this onbackpressed method in preferences.class (extends preferenceactivity):

    @override public void onbackpressed() {     //login again     intent intent = new intent(preferences.this, loginactivity.class);     startactivity(intent); } 

what need if-condition checks, if preferences changed or not.:

if user opens preferences activity (edit: view(!)), , not change , clicks backbutton -> go last state.

if preferences changed: call loginactivity.

couldnt find solution yet , loginactivity gets called whenever hit backbutton.

thanks in advance, marley

to determine if there change in sharedpreferences have assign onsharedpreferencechangelistener sharedpreferences object this:

prefs = preferencemanager.getdefaultsharedpreferences(this); prefs.registeronsharedpreferencechangelistener(this); 

in case i'm doing in application class that's implementing:

public class yambaappobj extends application implements onsharedpreferencechangelistener  

then have override:

public void onsharedpreferencechanged(sharedpreferences sharedpreferences, string key) {     //this method called when preferences changed.     //do here want record change     log.d(tag , "onsharedpreferencechanged for:" + key); } 

and check record in onbackpressed() method of preferences activity , act accordingly.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -