How to run pop up an dialog on background when the data matches within my code
<p>I have an <code>Date</code> array which stored dates and time in its respective positions in my app like:</p>

<pre><code>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
</code></pre>

<p>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 pop up one dialog with some information, similarly whenever my current date matches next date store in an array it again pop up an dialog. So this whole process should run whether my app is in running state or not in running state. So how that can be done. I go through many examples like <code>AlarmManager</code>, <code>IntetService</code>, Service, But not able to get the result that i want. So if anyone works in such issue, please help me to solve this out.</p>

<p><strong>Code of my main Activity</strong></p>

<pre><code>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></pre>

<p><strong>Code in my alarm service</strong></p>

<pre><code>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();
}
}
</code></pre>
