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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:17:28+00:00 2026-06-11T13:17:28+00:00

I have this code from where I can set a time and date from

  • 0

I have this code from where I can set a time and date from date picker and time picker at once:

 private void dialoguetime() {

    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.custom_dialogue);
    dialog.setCancelable(true);
    dialog.setTitle("This is Dialog 1");
    dialog.show();

    TimePicker time_picker = (TimePicker) dialog
            .findViewById(R.id.timePicker1);
    hours = time_picker.getCurrentHour();
    minute = time_picker.getCurrentMinute();
    time_picker.setOnTimeChangedListener(new OnTimeChangedListener() {
        public void onTimeChanged(TimePicker view, int hourOfDay,
                int minutes) {
            // TODO Auto-generated method stub
            // Toast.makeText(CustomDialog.this,
            // "hourOfDay = "+hourOfDay+"minute = "+minute , 1000).show();
            hours = hourOfDay;
            minute = minutes;
        }
    });

    final DatePicker date_picker = (DatePicker) dialog
            .findViewById(R.id.datePicker1);
    Button btn = (Button) dialog.findViewById(R.id.button2);
    btn.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            // TODO Auto-generated method stub



            xDate = date_picker.getYear() + "-"+ (date_picker.getMonth() + 1) + "-"+ date_picker.getDayOfMonth() + " " + hours+ ":" + minute + ":00";
            Toast.makeText(
                    getApplicationContext(),
                    xDate, Toast.LENGTH_LONG)
                    .show();
            dialog.cancel();
        }

    }

    );

}

From this I can get a string as a date format like this yyyy-mm-dd hh:mm:ss, now I want to give an alert (as alarm) to the user of that selected time. I have used alarm manager for this but it didn’t allow me to select that date?

How can I do this?

  • 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-11T13:17:30+00:00Added an answer on June 11, 2026 at 1:17 pm

    If you look at the API for AlarmManager (http://developer.android.com/reference/android/app/AlarmManager.html) you can see that the method

    set()
    

    requires the following parameters:

    public void set (int type, long triggerAtMillis, PendingIntent operation)
    

    where

    int type = One of ELAPSED_REALTIME, ELAPSED_REALTIME_WAKEUP, RTC or RTC_WAKEUP.
    long triggerAtMillis = time in milliseconds that the alarm should go off, using the appropriate clock (depending on the alarm type).
    PendingIntent operation = Action to perform when the alarm goes off
    

    So basicly what you should do, is to get the time between the selected date (DateFormat.parse() to parse the date-formated string to date) and the current date. Something like this:

    Date now = new Date();
    SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
    Date parsedDate = format.parse(YOUR_PICKED_DATE_AS_STRING);
    long alertTime = parsedDate.getTime() - now.getTime();
    
    Intent someIntent = new Intent(getApplicationContext(), YourClass.class);
    PendingIntent pending = PendingIntent.getBroadcast(getApplicationContext(), 0, someIntent, 0);
    
    AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    manager.set(AlarmManager.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this code from a tutorial: // Do the search and show the
I have this source code from 2001 that I would like to compile. It
I have this code that reads from XML file. It gets five strings (groupId,
Ok i have this piece of code from which i took from W3schools :-
I am using iTextSharp in VB.net. I have this piece of code from java
I have this Javascript code I inherited from another developer. I am very new
I have this code to update my SQL database from data in a textbox,
I have this code here printf '$request1 = select * from whatever where this
I have this code in my forms.py : from django import forms from formfieldset.forms
I have this code (which is way simplified from the real code): public interface

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.