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

  • Home
  • SEARCH
  • 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 6474307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:34:19+00:00 2026-05-25T06:34:19+00:00

I am creating an Android application, and I have a problem.(I am new to

  • 0

I am creating an Android application, and I have a problem.(I am new to Android development)

In my application, I want to set alarm for today. It works for that, but my problem is when I want to set time from time picker as less than the current time, my alarm rings immediately. I want to set that time for tomorrow’s time. How do I do that?

  • 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-25T06:34:20+00:00Added an answer on May 25, 2026 at 6:34 am

    Simply check the results of the time picker before setting the alarm. I’m not sure exactly how your setting your alarm, or what kind of alarm your even using, I will assume that given a time in millis you can work it out.

    public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
        Calendar now = Calendar.getInstance();
        Calendar alarm = Calendar.getInstance();
        alarm.set(Calendar.HOUR_OF_DAY, hourOfDay);
        alarm.set(Calendar.MINUTE, minute);
        long alarmMillis = alarm.getTimeInMillis();
        if (alarm.before(now)) alarmMillis+= 86400000L;  //Add 1 day if time selected before now
        setAlarm(alarmMillis);
    }
    
    public void setAlarm(long millis) { 
        /** Set your alarm here */
    }
    

    There are many other ways to do this, but I find the Calendar class is usually good for time manipulation for beginners. Hope this helps.

    EDIT:
    If DST is a concern, a small edit will solve the problem:

    public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
        Calendar now = Calendar.getInstance();
        Calendar alarm = Calendar.getInstance();
        alarm.set(Calendar.HOUR_OF_DAY, hourOfDay);
        alarm.set(Calendar.MINUTE, minute);
        if (alarm.before(now)) alarm.add(Calendar.DAY_OF_MONTH, 1);  //Add 1 day if time selected before now
        setAlarm(alarm.getTimeInMillis());
    }
    

    You will need to make sure the Time Zone is correctly set. The above code will use the Default Time Zone which is set by the System based on your Android Locale settings. Use Calendar.getInstance(TimeZone zone) to get the Calendar object in a specific Time Zone.

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

Sidebar

Related Questions

Actually, I am facing a problem in Android. I am creating an application that
I'm am creating an Android application, but in order to have one of the
i am new in android development and i have one problem with redirect the
Hi I have a problem creating a custom view for an Android application. My
I'm creating a splash screen that will display while my Android application loads. I'd
I am creating a file in my Android application as follows: HEADINGSTRING = new
I'm creating an Android application (Android 2.3.3) that has a header, a footer and
I am creating an Android application which will have some embedded music inside of
I am creating an android application in which I have to insert an image
I'm creating an android application and within it there is a button that will

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.