android - SharedPreferences and Countdown Timer: I can't save the time -
I am making a countdown timer and I am using this code. (For the first time sorry for my bad english) I use the time to share, when I return to any other activity and return, but when I return to the countdown activity, it restarts the timer Can not you save me anything else? This is the code used!
Public Class Main 8 Extends Extremity Activity OnClickListener {Myapp application; String eleg = ""; Calculation device timer start 1; Button claimant; Long cont = 0, q = 0; Personal SimpleDataFormat Time Format; @ Override Protected Zero (Bundle Saved Instantstate) {Super. NET (Saved Instantstate); RequestWindowFeature (Window.FEATURE_NO_TITLE); GetWindow () SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); SetContentView (R.layout.fragment8_main); Timeformat = New SimpleDateform ("HH: mm: SS"); Button SEG = (Button) findViewById (R.id.button1); // seguir seg.setOnClickListener (New OnClickListener) {@Override Public Zero onClick (see v) {// TODO Automatic Created Method Stub // L a temporizador (Q);}}); Button equal = (button) findViewById (R.id.button2); // seguir par.setOnClickListener (New OnClickListener) {@Override Public Zero onClick (see v) {// TODO Automatic Created Method Stub // L. A Parar ();}}); // to // temporizador (last long secondadd); Temporizador (600000); Override public zero at @BackPressed Super.onBackpressed (); This.finish (); } Public Zero Temporizador (last long secondadd) {start1 = new CountDownTimer (secondadd, 1000) {// to ejecuta al terminar el tiimpo, kuendo llega a 0 @Override public zero onFinish () {//contador.setText(String.valueOf (00 + ":" +00)); Contador.setText ("The time elapsed:" + time format.form (second edid)); Toast. Make Text (Main 8ctivity.es, "Termino L. Timpo", Toast. LNNGHHORART). Show (); The remaining part = 0; } // ejecuta por cada Segundo pasado @Override Public Zero onTick (long millisUntilFinished) {contador.setText ("time pass:" + timeFormat.format (secondadd)); Contador.setText (String.Format (timeFormat.format (millisUntilFinished)); // contador.setText (String.Format ("% 02d:% 02d:% 02d", millisUntilFinished / 3600, (millisUntilFinished% 3600) / 60, (millisUntilFinished 60%)); Remaining part = millisUntilFinished; Q = MillisNet finished; } }.Start(); } // Metode Parse LCUL Delivine El Timpo Del Contributor Public Video Pare () {start1.cancel (); } // Metodo OnDestri @ Override Protected Zero (Directive) {Super. One day (); Parar (); } // metodo onstop @Override Safe void onStop () {super.onStop (); // rescata el tiempo en el que seed with // int tiempokedo = Integer.parseInt ((contador.getText () + "000"). ToString ()); // A priority protected by al training priorities = priority manager .get default shared context (getApplicationContext ()); Editor editor = preferences.edit (); Editor.putLong ("stiem", the rest) Editor.commit (); // SE Deteny Elle Temorizador (Timpo) Parre (); } // Metodeo Restore Protected Zero () {Super. Share the previously shared option to share with preferences = preferencesManager.getDefaultSharedPreferences (this); Int tr = preferences.getInt ("stiem", 0); // re-enzia al thoromizad com to reset the al parameter which is working on time (tr); }
}
How you can learn and compile Are you trying to store as an integer without artists etc. for a long time?
Call getLong (String key, long defValue)
of onRestart (getInt (...) instead)
Comments
Post a Comment