preferenceactivity - Manipulate preference data in Android -


i have preference http timeout set in milliseconds on backend. when user edits it, want them able specify number in minutes.

i have looked @ (sharedpreferences.onsharedpreferencechangelistener not being called consistently) , looks possible add listener see when preference value changes. convert minutes milliseconds.

but how can i, when preference activity loads, convert milliseconds in minutes when user goes edit see minutes value?

hi need convert milliseconds minutes , second combination purpose can use following code snippet

long minutes = timeunit.milliseconds.tominutes(millis); long seconds = timeunit.milliseconds.toseconds(millis); 

or if wants go generic way than

seconds = (millis/ 1000) % 60; minutes = (millis/ (1000 * 60)) % 60; hours = (millis/ (1000 * 60 * 60)) % 24; 

note millis means milliseconds

and in reverce way can convert minutes millis

long t = (min * 60l) + sec;  long result = timeunit.seconds.tomillis(t); 

beside if wants detect if changes made on preferences==>

you need register listener register in onresume , unregister in onpause follows

@override protected void oncreate(bundle savedinstancestate) {     //...     prefs = preferencemanager.getdefaultsharedpreferences(this); }  @override protected void onresume() {     super.onresume();     prefs.registeronsharedpreferencechangelistener(this); }  @override protected void onpause() {           super.onpause();     prefs.unregisteronsharedpreferencechangelistener(this); } 

please visit

http://androidpartaker.wordpress.com/2012/02/05/change-preference-summary/

preference activity listener in android

http://developer.android.com/reference/android/preference/preference.onpreferencechangelistener.html


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -