How to save value in Sharedpreferences?

There is a code below.

Can not doperet how to keep the timer in Sharedpreferences, so that when closing the app it continued the countdown?

And if not difficult, tell me how to make timer displayed as 00:00 and then I got thousands =(

Make in Android Studio

import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


import java.io.IOException;


public class MainActivity<time> extends AppCompatActivity {
 //Declare the variables of the components
 Button button;
 TextView textView;
 TextView mTimer;
 SharedPreferences nTime;




 //Variable for DB
 private BDGuru mDBHelper;
 private SQLiteDatabase mDb;

@Override
 protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R. layout.activity_main);


 mDBHelper = new BDGuru(this);

 try {
mDBHelper.updateDataBase();
 } catch (IOException mIOException) {
 throw new Error("UnableToUpdateDatabase");
}

 try {
 mDb = mDBHelper.getWritableDatabase();
 } catch (SQLException mSQLException) {
 throw mSQLException;
}

 //Find components in XML markup
 button = (Button) findViewById(R. id.button);
 textView = (TextView) findViewById(R. id.textView);
 mTimer = (TextView) findViewById(R. id.mTimer);

 //Click on button
 button.setOnClickListener(new View.OnClickListener() {

@Override
 public void onClick(final View v) {
 String product = "";
 Cursor cursor = mDb.rawQuery("SELECT * FROM Guru ORDER BY RANDOM() LIMIT 1;", null);
cursor.moveToFirst();
 while (!cursor.isAfterLast()) {
 product = cursor.getString(1);
cursor.moveToNext();
}
cursor.close();

textView.setText(product);
v.setVisibility(View.GONE);

 int _12HoursInMilSecs = 12 * 60 * 60 * 1000;
 v.postDelayed(new Runnable() {
 public void run() {
v.setVisibility(View.VISIBLE);
}
 }, _12HoursInMilSecs);


 new CountDownTimer(_12HoursInMilSecs,1000) {

 public void onTick(long millisUntilFinished) {
 mTimer.setText("seconds remaining:" + millisUntilFinished / 1000);


}

 public void onFinish() {
mTimer.setText("");
}

}
.start();


}
});

}

}
March 25th 20 at 13:42
0 answer

Find more questions by tags AndroidJava