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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:29:50+00:00 2026-06-06T20:29:50+00:00

I have a Date array which stored dates and time in its respective positions

  • 0

I have a Date array which stored dates and time in its respective positions in my app like:

private Date    m_DateTimeArray[];

m_DateTimeArray = new Date[Utilities.DATE_TIME_MAX_COUNT];

m_DateTimeArray[0] = 1-july-2012 12:30:00
m_DateTimeArray[1] = 1-july-2012 01:00:00
m_DateTimeArray[2] = 1-july-2012 02:30:00
m_DateTimeArray[3] = 1-july-2012 03:15:00
m_DateTimeArray[4] = 1-july-2012 04:20:00
m_DateTimeArray[5] = 1-july-2012 05:00:00
m_DateTimeArray[6] = 1-july-2012 06:30:00

Now I exit my app, so now on the background what I want is, whenever my device current date matches this date stored in an array, it pops up one dialog with some information, similarly whenever my current date matches next date store in an array it again pop up a dialog. So this whole process should run whether my app is in a running state or not in a running state. So how that can be done. I go through many examples like AlarmManager, IntetService, Service, But not able to get the result that I want. So if anyone works on such issue, please help me to solve this out.

Code of my main Activity

public class AndroidAlarmService extends Activity 
{
private PendingIntent pendingIntent;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button buttonStart = (Button)findViewById(R.id.startalarm);
    Button buttonCancel = (Button)findViewById(R.id.cancelalarm);

    buttonStart.setOnClickListener(new Button.OnClickListener()
    {
        @Override
        public void onClick(View arg0) 
        {
            Intent myIntent = new Intent(AndroidAlarmService.this, MyAlarmService.class);
            pendingIntent = PendingIntent.getService(AndroidAlarmService.this, 0, myIntent, 0);

            AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);

            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(System.currentTimeMillis());
            calendar.add(Calendar.SECOND, 20);
            alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);

            Toast.makeText(AndroidAlarmService.this, "Start Alarm", Toast.LENGTH_LONG).show();
        }});

    buttonCancel.setOnClickListener(new Button.OnClickListener()
    {
        @Override
        public void onClick(View arg0) 
        {
            AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
            alarmManager.cancel(pendingIntent);
            
            // Tell the user about what we did.
            Toast.makeText(AndroidAlarmService.this, "Cancel!", Toast.LENGTH_LONG).show();
        }});

}
}

Code in my alarm service

public class MyAlarmService extends IntentService 
{   
public void onCreate() 
{
    super.onCreate();
}

public MyAlarmService() 
{
    super("MyAlarmService");
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) 
{
    super.onStartCommand(intent, startId, startId);
    Toast.makeText(this, "MyAlarmService.onStart()", Toast.LENGTH_LONG).show();
    return START_STICKY;
}
            
@Override
protected void onHandleIntent(Intent intent) 
{
    Toast.makeText(this, "MyAlarmService.onStart()", Toast.LENGTH_LONG).show();
}
}
  • 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-06T20:29:52+00:00Added an answer on June 6, 2026 at 8:29 pm

    There are 2 ways like Making one BroadCast Receiver with the Action TIME_TICK and Using AlarmManager, But as reading your requirement there is only one preffered way for you is to use AlarmManager.

    Whenever the data in the DATE Array generated you need to set one Alarm for each of the elements of the Array.

    I am sure you have tried many Examples available on net for the same, Then I tell you to use them again EXAMPLE you will use this example as it is, you will just have to change one thing in the code like where they haved added cal.add(Seconds,10); there instead of it you will have to add the difference of your current time and date array element time.

    The rest of the code from example will remain as it is.

    EDIT Trying To Write Code

        for(int i=0;i<dateArray.length();i++)
        {
        Intent myIntent = new Intent(AndroidAlarmService.this, MyAlarmService.class); 
        pendingIntent = PendingIntent.getService(AndroidAlarmService.this, 0, myIntent, 0); 
    
        AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); 
    
        Calendar calendar = Calendar.getInstance(); 
        calendar.setTimeInMillis(System.currentTimeMillis()); 
        calendar.add(Calendar.MILLISECOND, diff(dateArray[i])); 
        alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); 
    
        Toast.makeText(AndroidAlarmService.this, "Start Alarm", Toast.LENGTH_LONG).show(); 
        }
    
        long diff(Date date) {
            long difference = 0;
            try {
    
                // set current time
                Calendar c = Calendar.getInstance();
                difference = date.getTime() - c.getTimeInMillis();
                if (difference < 0) {
                    difference = difference * -1;
                    difference = 86400000 - difference;
                }
            } catch (Exception e) {
                // TODO: handle exception
            }
            return difference;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have retrieved few dates from an array ,which where stored in string format
i have take one string array which stored date in format of 2012-04-26T08:38:00. i
I have some code which builds an array of date ranges. I then call
I have an array that I would like to sort using a date field
I have a multi dimensional array, like this: array('name' => array('title'=>'Title','date'=>'Created')) I store it
I am new to iphone development .I have mutable array recent in which the
I'm putting some dates into an array, and would like to have a second
I have an array of Ruby Date objects. How can I find the newest
I have a date time property in a linq to sql model and I
I have a textbox which accepts Minutes. This value will be stored in a

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.