Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7781237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:09:47+00:00 2026-06-01T19:09:47+00:00

I have an activity that starts after a certain time. Once this activity starts,

  • 0

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 minutes until the button is pressed.

I have a listener for the button:

    startBreakButton = (Button) findViewById(R.id.startBreakButton);
    startBreakButton.setOnClickListener(mStartListener);

I have the code for displaying the toast and everything else is working well.

I’m just not sure where to put the code I want to run before the button is clicked. Within the mStartListener code or somewhere else such as within the onCreate method?

UPDATE

 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;

    }
    }
    };

EDIT – Above solution is not working, it needed to be clicked==false, not clicked=false!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:09:49+00:00Added an answer on June 1, 2026 at 7:09 pm

    Try like this..

    in oncreate create a acountdowntimer..

     MyCount counter;
     counter=new MyCount(300000,1000);
     counter.start();
    

    MyCount class..

       public class MyCount extends CountDownTimer{
    public MyCount(long millisInFuture, long countDownInterval) {
    super(millisInFuture, countDownInterval);
    }
    @Override
    public void onFinish() {
      if(clicked=false){
      //put the toast here
        counter= new MyCount(300000,1000);
     counter.start();
        }
    
    }
    @Override
    public void onTick(long millisUntilFinished) {
        s1=millisUntilFinished;
    
    
    
    }
    }
    }
    

    and in onclicklistener of startBreakButton put

    clicked=true;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity that starts after a certain time. Once this activity starts,
I have 4 buttons that when click starts a new activity class. This works
I have an Activity that starts a Service. In my Activity: startService(new Intent(this, MyService.class));
In my application, after the user presses the appropriate button, an activity starts that
So I have a very simple android activity that starts a timer when you
I have an activity that lets the user load some data when they press
I have a Notification which starts an Activity. After a long press on home
I have an single Activity application that starts a Service and binds to it.
I have an activity that contains several user editable items (an EditText field, RatingBar,
i have a default activity that starts first (Activity A), and from there the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.