0

In my task, I have perform the Reminder Checking process. If the reminder time comes to equal the Current time it will raise a pop-up box. In this Task the pop-up box Comes correctly.

But if i Merge this task to a Some big process, Which means the Reminder task will be a Sub-program of the main program. The Pop-up not coming in the other Screens. If the Time Met the Current time, the alert must shown to the User, while the user using any of the Screen in this Program..

if (LDbTime <= LSysTime) {
                                    rem_id = c.getString(c.getColumnIndex("reminder_id"));
                                    remName = c.getString(c.getColumnIndex("rname"));
                                    mediaPlayer.start();
                                    handler.post(new Runnable(){
                                    public void run() {
                                        alert.setTitle("Alert :"+remName);
                                        alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                mediaPlayer.pause();
                                            }
                                        });
                                        alert.show();
                                        db1.execSQL("UPDATE RemainAlarmS SET expired ='TRUE' WHERE reminder_id = " + rem_id );
                                            }
                                        });
                                    Thread.sleep(5000);
                                }

In this Alert message needs to Bring for Front Screen at the time of Reminder wake-up.

Please Help me to find the Solution..

Thanks in Advance.

gowri
  • 681
  • 9
  • 27

3 Answers3

2

If you're trying to ask how to show a dialog when your activity is not the focused activity on the user's phone then try using Notifications instead. Popping up a dialog over a different application interrupts the user when they may be doing something else. From the Android UI guidelines:

Use the notification system — don't use dialog boxes in place of notifications

If your background service needs to notify a user, use the standard notification system — 
don't use a dialog or toast to notify them. A dialog or toast would immediately 
take focus    and interrupt the user, taking focus away from what they were doing: 
the user could be in the middle of typing text the moment the dialog appears 
and could accidentally act on the dialog. 
Users are used to dealing with notifications and 
can pull down the notification shade at their convenience to respond to your message.

A guide to create notifications is here: http://developer.android.com/guide/topics/ui/notifiers/notifications.html

SunnySonic
  • 1,318
  • 11
  • 37
2

You Can use the Following codes for the Pending Intent..

Intent i = new Intent("android.intent.action.DA");
PendingIntent operation = PendingIntent.getActivity(getBaseContext(), 0, i, Intent.FLAG_ACTIVITY_NEW_TASK);
AlarmManager alarmManager = (AlarmManager) getBaseContext().getSystemService(ALARM_SERVICE);
GregorianCalendar calendar = new GregorianCalendar(y,m,d, hr, mi);
long alarm_time = calendar.getTimeInMillis();
alarmManager.set(AlarmManager.RTC_WAKEUP  , alarm_time , operation);

And the "android.intent.action.DA" denotes the Activity of the DisplayNotification.java class

public class DisplayNotification extends Activity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int notifID = getIntent().getExtras().getInt("NotifID");
    Intent i = new Intent("android.intent.action.AD");
    i.putExtra("NotifID", notifID);  
    PendingIntent detailsIntent =PendingIntent.getActivity(this, 0, i, 0);
    NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    Notification notif = new Notification(R.drawable.ic_launcher,"Time's up!",System.currentTimeMillis());
    CharSequence from = "AlarmManager - Time's up!";
    CharSequence message = "This is your alert, courtesy of the AlarmManager";        
    notif.setLatestEventInfo(this, from, message, detailsIntent);
    notif.vibrate = new long[] { 100, 250, 100, 500};        
    nm.notify(notifID, notif);
    finish();
}
}

And the "android.intent.action.AD" denotes the AlarmDetails.java class

public class AlarmDetails extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.alarmdetails);

    NotificationManager nm = (NotificationManager) 
            getSystemService(NOTIFICATION_SERVICE);
        //---cancel the notification---
        nm.cancel(getIntent().getExtras().getInt("NotifID")); 
}

}

I hope this will help you!..

MGR
  • 382
  • 2
  • 7
  • 21
-1

You could use status bar notifications instead.

SunnySonic
  • 1,318
  • 11
  • 37