Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pause and start the timer in android?
    primarykey
    data
    text
    <p>I am working on android applications. In my project I have 3 pages.<br></p> <ul> <li>The first page consists of 1 button. </li> <li>The second page is consists of the timer code. </li> <li>The third page consists of again a button.</li> </ul> <p>Now my requirement is when I click on the first page button the third page should open and the timer in second page should pause. Again when I click on the third page button the second page <strong>timer should restart the time where it is stopped</strong> and should open the first page. </p> <p>I am struggling to achieve this task.Guide me through it, Suggest what should have been done to do that.</p> <pre><code>Page1.java rowTextView.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent myIntent = new Intent(v.getContext(),Page3.class); startActivity(myIntent); finish(); } }); Page2.java public class TimeractivitybestActivity extends Activity { EditText e1; MyCount counter; Long s1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); e1 = (EditText) findViewById(R.id.editText1); counter = new MyCount(15000, 1000); counter.start(); } public void method(View v) { switch (v.getId()) { case R.id.button1: counter.cancel(); break; case R.id.button2: counter = new MyCount(s1, 1000); counter.start(); } } public class MyCount extends CountDownTimer { public MyCount(long millisInFuture, long countDownInterval) { super(millisInFuture, countDownInterval); } @Override public void onFinish() { e1.setText("DONE"); } @Override public void onTick(long millisUntilFinished) { s1 = millisUntilFinished; e1.setText("left:" + millisUntilFinished / 1000); } } } Page3.java public void gobacktopage1(View v) { Intent myIntent = new Intent(v.getContext(),Page1.class); startActivity(myIntent); finish(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload