私のアプリケーションにはテキストビューとボタンがあります。私がボタンをタッチするとカウントダウンが始まりますが、アプリケーションを終了して再び開くとCountDownは0に戻ります。カウントダウンを保存するにはどうしたらいいですか?それは共有プリファレンスを持っていますか?間違いなくアンドロイドスタジオのCountDownを保存
public class MainActivity extends Activity {
Button b1;
TextView tv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1 = (TextView) findViewById(R.id.tv1);
b1 = (Button) findViewById(R.id.b1);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu
// this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void a(View view){
new CountDownTimer(10000, 1000) {
public void onTick(long millisUntilFinished) {
tv1.setText("La cuenta llega a 0 en: " + millisUntilFinished/1000);
}
public void onFinish() {
tv1.setText("Listo!");
}
}.start();
}
}
もののに役立つことを願っています
今デシベルで、カウントを保存するためには、これらの
を使用する必要があり、:あなたはこれらのようにコーディングする必要がこれらのオプションにはdbは大量に殺すことです。共有プレファレンスは確かに行く方法です。 – Geoff
こんにちは、申し訳ありませんが私は自分自身を説明していない、私が必要なものは、カウントダウンを保存すると、私は閉じると、アプリを開いてカウントダウンはまだ実行したい –