I have an activity that starts after a certain time. Once this activity starts, the user is supposed to press a button that starts a new timer.
However, if the user does not press the button I want a toast to be displayed every 5 seconds until the button is pressed.
I m trying to use a CountDownTimer. Here is the basics of the code I have so far:
I have no errors but no toasts are being displayed at the moment. Is it ok to have the MyCount class inside the BreakActivity class (if i put it outside I get an error).
Any help in getting this sorted will be greatly appreciated!
public class BreakActivity extends Activity {
Button startBreakButton; // button to start the break timer
Boolean clicked= false;
CountDownTimer counter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.breakscreen); // sets layout to breakscreen.xml
MyCount counter;
counter=new MyCount(5000,1000);
counter.start();
startBreakButton = (Button) findViewById(R.id.startBreakButton);
startBreakButton.setOnClickListener(mStartListener);
View.OnClickListener mStartListener = new OnClickListener() {
clicked=true;
//other listener code
};
public class MyCount extends CountDownTimer{
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
if(clicked=false){
Toast.makeText(getApplicationContext(), "TAKE A BREAK", Toast.LENGTH_LONG).show();
counter= new MyCount(5000,1000);
counter.start();
}
}
@Override
public void onTick(long millisUntilFinished) {
long s1 = millisUntilFinished;
}
}
};