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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:40:24+00:00 2026-05-23T18:40:24+00:00

I want to create an alarm object from my application. I am writing a

  • 0

I want to create an alarm object from my application. I am writing a To-Do application which will have an option to set an Alarm on the phone.

I wanna set the Date and Time and also the Label for the alarm.

Calendar c = Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
        c.clear();
        c.set(Calendar.YEAR, mYear);
        c.set(Calendar.MONTH, mMonth);
        c.set(Calendar.DAY_OF_MONTH, mDay);
        c.set(Calendar.HOUR, mHour);
        c.set(Calendar.MINUTE, mMinute);
        Intent activate = new Intent(this, alaram.class);
        AlarmManager alarams ;
        PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 0, activate, 0);
        alarams = (AlarmManager) getSystemService(this.ALARM_SERVICE);
        alarams.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), alarmIntent);

I tried using the above code to set the alarm but am not able to. I dont get any error either 🙁

  • 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-05-23T18:40:25+00:00Added an answer on May 23, 2026 at 6:40 pm

    As @stealthcopter said, the AlarmManager is used to raise an Alarm your application can catch and then do something. Here is a little example I threw together from other posts, tutorials, and work I’ve done.

    Main.java

    Intent i = new Intent(this, OnAlarmReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(this, 0, i,
                                                         PendingIntent.FLAG_ONE_SHOT);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.SECOND, calendar.get(Calendar.SECOND) + 10);
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pi);
    

    OnAlarmReceiver.java

    public class OnAlarmReceiver extends BroadcastReceiver{
    
    @Override
    public void onReceive(Context context, Intent intent) {
        WakeIntentService.acquireStaticLock(context);
        Intent i = new Intent(context, AlarmService.class);
        context.startService(i);
    }}
    

    WakeIntentService.java

    public abstract class WakeIntentService extends IntentService {
    
        abstract void doReminderWork(Intent intent);
    
        public static final String LOCK_NAME_STATIC = "com.android.voodootv.static";
        private static PowerManager.WakeLock lockStatic = null;
    
        public static void acquireStaticLock(Context context) {
            getLock(context).acquire();
        }
    
        synchronized private static PowerManager.WakeLock getLock(Context context) {
            if (lockStatic == null) {
                PowerManager powManager = (PowerManager) context
                        .getSystemService(Context.POWER_SERVICE);
                lockStatic = powManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                        LOCK_NAME_STATIC);
                lockStatic.setReferenceCounted(true);
            }
            return (lockStatic);
        }
    
        public WakeIntentService(String name) {
            super(name);
        }
    
        @Override
        final protected void onHandleIntent(Intent intent) {
            try {
                doReminderWork(intent);
            } finally {
                getLock(this).release();
            }
        }}
    

    AlarmService.java

    public class AlarmService extends WakeIntentService {
    
        public AlarmService() {
            super("AlarmService");
        }
    
        @Override
        void doReminderWork(Intent intent) {
            NotificationManager manager = (NotificationManager)
                    getSystemService(NOTIFICATION_SERVICE);
            Intent notificationIntent = new Intent(this, Main.class);
            PendingIntent pi = PendingIntent.getActivity(this, 0,
                    notificationIntent, PendingIntent.FLAG_ONE_SHOT);
            Notification note = new Notification(R.drawable.icon, "Alarm",
                    System.currentTimeMillis());
            note.setLatestEventInfo(this, "Title", "Text", pi);
            note.defaults |= Notification.DEFAULT_ALL;
            note.flags |= Notification.FLAG_AUTO_CANCEL;
            int id = 123456789;
            manager.notify(id, note);
        }
    }
    

    This example will create a notification on the status bar after 10 seconds.

    Hope it helps.

    Also First post here 🙂

    Oh almost forgot,

    AndroidManifest.xml

    <receiver android:name="com.android.alarmmanagertest.OnAlarmReceiver" />
    <service android:name="com.android.alarmmanagertest.AlarmService" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Homework Planner application which I want to create an Alarm for
Want to create an alarm application, that will play a music file at a
I want to create alarm inside an application at a particular Date & Time.
Currently I have a timer with an alarm (local notification). I want to create
I'm not really writing an alarm clock application, but it will help to illustrate
I want to create an alarm app in wp7. I can set basic alarms
im trying to create an alarm clock application which do a spesific actions once
UNIQLO's new alarm app has a custom UIDatePicker : And I want to create
i want create multiple search where statement $where_search is a multiple condition from post
I want create wordpress website into which I want create user management... That means

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.