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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:53:27+00:00 2026-06-09T14:53:27+00:00

Please excuse me if this is a noob question. I have tried every possibility

  • 0

Please excuse me if this is a noob question. I have tried every possibility I could to set five alarms daily from the five edit texts. But nothing worked! I also have a button (not shown in this code) which updates these edit texts (therefore should update the alarm times as well). Here’s my code:

for (int i = 0; i < 5; i++) {
            switch (i) {
            case 0:
                fajr.setText(result[i]);
                tFajr = new GregorianCalendar();
                tFajr.set(year, month, day,
                        Integer.parseInt(result[i].substring(0, 2)),
                        Integer.parseInt(result[i].substring(3, 5)));
                break;
            case 1:
                zuhr.setText(result[i]);
                tZuhr = new GregorianCalendar();
                tZuhr.set(year, month, day,
                        Integer.parseInt(result[i].substring(0, 2)),
                        Integer.parseInt(result[i].substring(3, 5)));
                break;
            case 2:
                asr.setText(result[i]);
                tAsr = new GregorianCalendar();
                tAsr.set(year, month, day,
                        Integer.parseInt(result[i].substring(0, 2)),
                        Integer.parseInt(result[i].substring(3, 5)));
                break;
            case 3:
                maghrib.setText(result[i]);
                tMaghrib = new GregorianCalendar();
                tMaghrib.set(year, month, day,
                        Integer.parseInt(result[i].substring(0, 2)),
                        Integer.parseInt(result[i].substring(3, 5)));
                break;
            case 4:
                isha.setText(result[i]);
                tIsha = new GregorianCalendar();
                tIsha.set(year, month, day,
                        Integer.parseInt(result[i].substring(0, 2)),
                        Integer.parseInt(result[i].substring(3, 5)));
                break;
            }
        }

P.S: fajr,zuhr,asr,maghrib,isha are the five EditTexts. I tried to use a pending intent and an alarm manager to fire the alarms but it didnt work. Does any one have a good suggestion?

  • 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-09T14:53:29+00:00Added an answer on June 9, 2026 at 2:53 pm

    First of all you need to declare a pending intent for each of the alarms. So if you want 5 alarms you will need to run it 5 times

    PendingIntent sender = PendingIntent.getBroadcast(context,intent_code, intent, 0);
    

    and the intent_code should change as well. Every time you register a new one you have to use a different code. In my application I have a random number generated every time that is executed. You can also pass data to your notification trough here using the Intent. Mind the difference between Intent and PendingIntent.

    Intent intent = new Intent(context, AlarmReceiver.class);
    intent.putExtra("title", "some title");
    intent.putExtra("notes","some notes");
    Random r = new Random();
    intent_code = r.nextInt();
    PendingIntent sender = PendingIntent.getBroadcast(context,intent_code, intent, 0);
    

    After that you need to register your alarm. Again 5 times, one for each alarm you want to trigger.

    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP, Time_in_milis_from_now_till_your_alarm, sender);
    

    You need a BroadcastReceiver to receive your alarm and display the notification. I am pasting my whole class. This will be triggered after the time set in the Time_in_milis_from_now_till_your_alarm. And you can run pretty much whatever you like in here. I don’t know what kind of alarm you want, in my case I’m using a notification. You can find the details about the notification here and here.

    public class AlarmReceiver extends BroadcastReceiver {
    
        @Override
         public void onReceive(Context context, Intent intent) {
            Log.d("receiver", "received");
            NotificationManager mManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            Bundle b = intent.getExtras();
    
    
            int icon = R.drawable.icon; // icon from resources
            CharSequence tickerText = b.getString("title"); ; // ticker-text
            long when = System.currentTimeMillis(); // notification time
            CharSequence contentText = b.getString("notes");; // message text
            Toast.makeText(context, tickerText, Toast.LENGTH_SHORT).show();
    
            Intent notificationIntent = new Intent(context, AppDelegate.class);
    
            // notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            PendingIntent contentIntent = PendingIntent.getActivity(context, 
                                                                    0, 
                                                                    notificationIntent,
                                                                    Intent.FLAG_ACTIVITY_NEW_TASK);
    
            // the next two lines initialize the Notification, using the
            // configurations above
            Notification notification = new Notification(icon, tickerText, when);
            notification.setLatestEventInfo(context,tickerText, contentText, contentIntent);
    
            mManager.notify(12, notification);
         }
    
    }
    

    Last, don’t forget to declare your broadcast in the manifest or it wont work. This goes inside application tag.

    If you have any problems with the alarm manager methods you can find the documentation here.

    All the best!

    Edit

    To play a sound use the MediaPlayer as recomended by the developer’s guide. Keep the file mysound.mp3 in your folder /res/raw. And you just call the following method in your BroadcastReceiver!

    public void playSound() {                
         MediaPlayer sound = MediaPlayer.create(this, R.raw.mysound);
         sound.setOnCompletionListener(new OnCompletionListener() {
         @Override
         public void onCompletion(MediaPlayer mp) {
                mp.release();
         }
    
         });
    
        quadrantChangeSound.start();
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please excuse the noob-ish nature of this question. I have a project in which
Please excuse me if this question is really obvious but i've tried everything. I
I'm new to EF so please excuse me if this is a noob question.
Please excuse me if this is a bit of a noob issue: I have
I am a patterns newbie so please excuse this question if it sounds too
I am new to jquery so please excuse me if this question seems silly...
This is my first post on stackoverflow, so please excuse me if my question
Please excuse my newbie Question. I'm tryin to display data from a mysql table
I'm a Grails noob so please excuse my noob question. I've created a domain
I'm a noob to Cocoa programming, so please excuse the possible stupidity of this

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.