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 8685559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:36:34+00:00 2026-06-12T22:36:34+00:00

I have a program that allows users to input three times for alarm, then

  • 0

I have a program that allows users to input three times for alarm, then at the appropriate time, display an alert.However, whenever i set the alarms, only the last one is being carried out.

So basically, the user inputs 1,2 or 3 then i carry out the number of time selection dialogs, then send those times to the alarm receiver. But only the last alarm is being carried out. Any help is appreciated. Apologies for length of code, it’s very inefficient i know.

Alarm Activity snippet::

buttonSetTime.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                if(alarmNumInt == 1){
                tvSet.setText("");
                openTimePicker1(false);
                }
                else if (alarmNumInt == 2){
                    tvSet2.setText("");
                    openTimePicker2(false);
                    tvSet.setText("");
                    openTimePicker1(false);

                    }
                else {
                tvSet3.setText("");
                openTimePicker3(false);
                tvSet2.setText("");
                openTimePicker2(false);
                tvSet.setText("");
                openTimePicker1(false);
                }
            }
        });


    protected void openTimePicker1(boolean b) {
        // TODO Auto-generated method stub
          Calendar calendar = Calendar.getInstance();

          timePromptDia = new TimePickerDialog(
            AlarmActivity.this, 
            onTimeSetListener, 
            calendar.get(Calendar.HOUR_OF_DAY), 
            calendar.get(Calendar.MINUTE), 
            b);
          timePromptDia.setTitle("Set Alarm 1 Time");  

          timePromptDia.show();

         }

    protected void openTimePicker2(boolean b) {
        // TODO Auto-generated method stub
          Calendar calendar = Calendar.getInstance();

          timePromptDia2 = new TimePickerDialog(
            AlarmActivity.this, 
            onTimeSetListener2, 
            calendar.get(Calendar.HOUR_OF_DAY), 
            calendar.get(Calendar.MINUTE), 
            b);
          timePromptDia2.setTitle("Set Alarm 2 Time");  

          timePromptDia2.show();

         }

    protected void openTimePicker3(boolean b) {
        // TODO Auto-generated method stub
          Calendar calendar = Calendar.getInstance();

          timePromptDia3 = new TimePickerDialog(
            AlarmActivity.this, 
            onTimeSetListener3, 
            calendar.get(Calendar.HOUR_OF_DAY), 
            calendar.get(Calendar.MINUTE), 
            b);
          timePromptDia3.setTitle("Set Alarm 3 Time");  

          timePromptDia3.show();

         }

          OnTimeSetListener onTimeSetListener = new OnTimeSetListener(){

          public void onTimeSet(TimePicker view, int hourOfDay, int minute) {       
           Calendar calNow = Calendar.getInstance();
           Calendar calSet = (Calendar) calNow.clone();

           calSet.set(Calendar.HOUR_OF_DAY, hourOfDay);
           calSet.set(Calendar.MINUTE, minute);
           calSet.set(Calendar.SECOND, 0);
           calSet.set(Calendar.MILLISECOND, 0);

           if(calSet.compareTo(calNow) <= 0){
            //Today Set time passed, count to tomorrow
            calSet.add(Calendar.DATE, 1);
           }
           setAlarm(calSet);
           //condition for other alarms

          }};

          OnTimeSetListener onTimeSetListener2 = new OnTimeSetListener(){

              public void onTimeSet(TimePicker view, int hourOfDay, int minute) {                   
               Calendar calNow = Calendar.getInstance();
               Calendar calSet = (Calendar) calNow.clone();

               calSet.set(Calendar.HOUR_OF_DAY, hourOfDay);
               calSet.set(Calendar.MINUTE, minute);
               calSet.set(Calendar.SECOND, 0);
               calSet.set(Calendar.MILLISECOND, 0);

               if(calSet.compareTo(calNow) <= 0){
                //Today Set time passed, count to tomorrow
                calSet.add(Calendar.DATE, 1);
               }
               setAlarm2(calSet);
               }};


           OnTimeSetListener onTimeSetListener3 = new OnTimeSetListener(){

                      public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

                       Calendar calNow = Calendar.getInstance();
                       Calendar calSet = (Calendar) calNow.clone();

                       calSet.set(Calendar.HOUR_OF_DAY, hourOfDay);
                       calSet.set(Calendar.MINUTE, minute);
                       calSet.set(Calendar.SECOND, 0);
                       calSet.set(Calendar.MILLISECOND, 0);

                       if(calSet.compareTo(calNow) <= 0){
                        //Today Set time passed, count to tomorrow
                        calSet.add(Calendar.DATE, 1);
                       }
                       setAlarm3(calSet);
                       }};

            protected void setAlarm(Calendar targetCal) {
                // TODO Auto-generated method stub


                  Intent intent1 = new Intent(getBaseContext(), AlarmReceiver.class);
                  PendingIntent pendingIntent1 = PendingIntent.getBroadcast(getBaseContext(), req, intent1, 0);
                  AlarmManager alarmManager1 = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
                  alarmManager1.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), pendingIntent1);
                   alarmManager1.setRepeating(AlarmManager.RTC_WAKEUP, 
                             targetCal.getTimeInMillis(), 
                             TimeUnit.HOURS.toMillis(24),
                             pendingIntent1);

                   tvSet.setText("Alarm 1 is set @ " + targetCal.getTime() + "\n" +" Repeat everyday\n");


            }

            protected void setAlarm2(Calendar targetCal2) {
                // TODO Auto-generated method stub


                  Intent intent2 = new Intent(getBaseContext(), AlarmReceiver.class);
                  PendingIntent pendingIntent2 = PendingIntent.getBroadcast(getBaseContext(), req2, intent2, 0);
                  AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
                  alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal2.getTimeInMillis(), pendingIntent2);
                   alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 
                             targetCal2.getTimeInMillis(), 
                             TimeUnit.HOURS.toMillis(24),
                             pendingIntent2);

                   tvSet2.setText("Alarm 2 is set @ " + targetCal2.getTime()+" Repeat everyday\n");
            }

            protected void setAlarm3(Calendar targetCal3) {
                // TODO Auto-generated method stub


                  Intent intent3 = new Intent(getBaseContext(), AlarmReceiver.class);
                  PendingIntent pendingIntent3 = PendingIntent.getBroadcast(getBaseContext(), req3, intent3, 0);
                  AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
                  alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal3.getTimeInMillis(), pendingIntent3);
                   alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 
                             targetCal3.getTimeInMillis(), 
                             TimeUnit.HOURS.toMillis(24),
                             pendingIntent3);

                   tvSet3.setText("Alarm 3 is set @ " + targetCal3.getTime() + " Repeat everyday\n");         
            }   
}

And the broadcast receiver activity:

    public class AlarmReceiver extends BroadcastReceiver {
 @Override
 public void onReceive(Context arg0, Intent arg1) {

     playSound();
     Toast toast;
     toast = Toast.makeText(arg0, "Time for Blood Glucose Testing!", Toast.LENGTH_LONG); 
     toast.setGravity(Gravity.CENTER, 0,0); 
     toast.show();
     Vibrator vibrator = (Vibrator) arg0.getSystemService(Context.VIBRATOR_SERVICE);
     vibrator.vibrate(1000);

  }
 public void playSound(){
     ToneGenerator alertTone = new ToneGenerator(AudioManager.STREAM_DTMF,ToneGenerator.MAX_VOLUME);
     alertTone.startTone(ToneGenerator.TONE_DTMF_1, 1000);
 }

}
  • 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-12T22:36:35+00:00Added an answer on June 12, 2026 at 10:36 pm

    What are the values of req, req2 and req3? These need to be different for each alarm.

    Also, I don’t think this will solve your issue, but you don’t need to call set() & setRepeating() on AlarmManager, just one or the other.

    Either call set() and reset the alarm yourself when the alarm occurs or let AlarmManager handle resetting by using setRepeating().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created the output for a program that allows a user to input
I have a program that allows the user to enter a level number, and
I have a program that only allows one instance of itself to run. I
I have program that has a variable that should never change. However, somehow, it
I have a program that saves an image in a local directory and then
I have a program that has this code : #include<stdio.h> main(){ int input; char
I'm making a mock-media player program that allows the user to input,edit,delete and view
I'm doing a magicsquare program that allows a user to input numbers >0 to
I'm working on a library that allows users to input arbitrary expressions. My library
I have a program that allows the user to draw vertices and edges on

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.