java - New Preferences not loading when back button is pressed -


i have preferences class (below) saves 2 listpreferences, if listpreferences changed , button pressed, changes don't take affect unless application restarted. did miss something? have been looking everywhere, can't seem find answer fits or works. please help.

    public class preferences extends preferenceactivity {        @override       public void oncreate(bundle savedinstancestate){            super.oncreate(savedinstancestate);            addpreferencesfromresource(r.xml.preferences);            }        @override       public void onpause() {            super.onpause();            }        @override       public void onresume() {            super.onresume();            }       } 

application code

 public class quotes extends activity implements onclicklistener {   progressdialog dialog;  private webview webview;   @override  public void oncreate(bundle savedinstancestate) {       super.oncreate(savedinstancestate);       setcontentview(r.layout.main);        sharedpreferences sp = preferencemanager.getdefaultsharedpreferences(getbasecontext());        string q = sp.getstring("appviewtype","http://www.google.com");       string c = sp.getstring("apprefreshrate","20");        webview = (webview) findviewbyid(r.id.scroll);       webview.getsettings().setjavascriptenabled(true);       webview.setwebviewclient(new quoteswebview(this));       webview.loadurl(q);        scheduledexecutorservice timer = executors.newsinglethreadscheduledexecutor();       timer.scheduleatfixedrate(new runnable() {        @override       public void run() {            webview.reload();            }        }, 10, long.parselong(c),timeunit.seconds);        findviewbyid(r.id.refresh).setonclicklistener(this);  }        @override       public void onpause(){            super.onpause();            }        @override       public void onresume(){            super.onresume();            }        public void onclick(view v){            switch(v.getid()){                 case r.id.refresh:                 webview.reload();            break;       }  }    @override  public boolean oncreateoptionsmenu(menu menu) {       menuinflater inflater = getmenuinflater();       inflater.inflate(r.menu.menu, menu);        menuitem = menu.getitem(0);       about.setintent(new intent(this, about.class));        menuitem preferences = menu.getitem(1);       preferences.setintent(new intent(this, preferences.class));        return true;        }   }    

you need somehow reload preferences when preferences activity finishes. thought dirol's suggestion of loading them in onresume() instead of oncreate() excellent; have tried it? or misunderstanding problem well.

in own case, launched preferences activity startactivityforresult() , on activity result callback, reloaded preferences.

code snippets:

@override public boolean onoptionsitemselected(menuitem item) {     switch (item.getitemid()) {       case menu_preferences:         intent intent = new intent().setclass(this, calcpreferences.class);         startactivityforresult(intent, menu_preferences);         break;       default: return super.onoptionsitemselected(item);     }     return true; }  @override protected void onactivityresult(int req, int result, intent data) {     switch( req ) {       case menu_preferences:         sharedpreferences sp =           preferencemanager.getdefaultsharedpreferences(this);         updatepreferences(sp);         break;       default:         super.onactivityresult(req, result, data);         break;     } }  @override protected void updatepreferences(sharedpreferences sp) {     super.updatepreferences(sp);     keyclick = sp.getboolean("keyclick", keyclick); } 

anyway, works me. may try moving updatepreferences() call onresume() myself see if works too.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -