android - SharedPreferences and Countdown Timer: I can't save the time -



android - SharedPreferences and Countdown Timer: I can't save the time -

i create countdown timer , utilize code. (first sorry bad english). utilize sharedpreferences save time when go activity , return, when returned countdown activity, restart timer , not save anything. can help me please? code used that!

public class main8activity extends activity implements onclicklistener { myapp application ; string eleg=""; countdowntimer start1; button contador; long cont=0,q=0; private simpledateformat timeformat; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); setcontentview(r.layout.fragment8_main); timeformat = new simpledateformat("hh:mm:ss"); button seg= (button) findviewbyid(r.id.button1);//seguir seg.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub //el temporizador(q); } }); button par= (button) findviewbyid(r.id.button2);//seguir par.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub //el parar(); } }); //te //temporizador(final long secondadd); temporizador(600000); @override public void onbackpressed() { super.onbackpressed(); this.finish(); } public void temporizador(final long secondadd){ start1 = new countdowntimer(secondadd, 1000) { //se ejecuta al terminar el tiempo,cuando llega 0 @override public void onfinish() { //contador.settext(string.valueof(00+":"+00)); contador.settext("time elapsed: " + timeformat.format(secondadd)); toast.maketext(main8activity.this, "se terminó el tiempo", toast.length_short).show(); cont=0; } //se ejecuta por cada segundo pasado @override public void ontick(long millisuntilfinished) { contador.settext("time elapsed: " + timeformat.format(secondadd)); contador.settext(string.format(timeformat.format(millisuntilfinished))); // contador.settext( string.format("%02d:%02d:%02d", millisuntilfinished / 3600,(millisuntilfinished % 3600) / 60, (millisuntilfinished % 60))); cont=millisuntilfinished; q= millisuntilfinished; } }.start(); } //metodo parar el cual detiene el tiempo del contador public void parar(){ start1.cancel(); } //metodo ondestroy @override protected void ondestroy() { super.ondestroy(); parar(); } //metodo onstop @override protected void onstop() { super.onstop(); //se rescata el tiempo en el que se quedo // int tiempokedo=integer.parseint((contador.gettext()+"000").tostring()); //el tiempo se guarda en united nations preferences sharedpreferences preferences=preferencemanager.getdefaultsharedpreferences(getapplicationcontext()); editor editor=preferences.edit(); editor.putlong("stiem",cont); editor.commit(); //se detiene el temporizador(tiempo) parar(); } //metodo onrestart protected void onrestart() { super.onrestart(); //se rescata de preferencias el valor del tiempo el cual se quedo sharedpreferences preferences=preferencemanager.getdefaultsharedpreferences(this); int tr=preferences.getint("stiem",0 );//re //se envia al temporizador con el parametro rescatado para que siga el tiempo temporizador(tr); }

}

how able compile knowing trying store long int without cast etc ?

call getlong(string key, long defvalue) instead of getint(...) in onrestart()

android timer sharedpreferences countdowntimer

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -