0

We have an alert screen that warns the user of a problem they need to fix.

I have been given a task to make this alert re-appear if the user hits the home button and goes about their business. (This is a critical problem that needs to be fixed.)

So I added this code to the onPause event:

    Handler handler = new Handler();
    handler.postDelayed(new Redisplay(), REDISPLAY_DELAY);

Which will give the user about 10 seconds and then run this:

private class Redisplay implements Runnable {
    @Override
    public void run() {
        log.fatal("Redisplaying:" + ending);
        if(!ending){
            Intent intent = new Intent(getApplicationContext(), UntetheredAlertActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            startActivity(intent);
        }
    }
}

Only this doesn't make my application the current application. Does anyone know how to do this?

Thom
  • 14,013
  • 25
  • 105
  • 185
  • I think you should consider to use the [AlarmManager](http://developer.android.com/reference/android/app/AlarmManager.html) . Each time you need to reschedule the redisplay of your Activity, you simply have to set a new alarm, using the AlarmManager – GVillani82 May 14 '15 at 15:04
  • @Joseph82 According to the docs, PendingIntent will be just like calling Context.startActivity() so how will this be better? – Thom May 14 '15 at 15:15
  • This is called "start activity from service": http://stackoverflow.com/a/3607934/755804 and http://stackoverflow.com/questions/7050027/how-do-you-start-an-activity-with-alarmmanager-in-android – 18446744073709551615 May 14 '15 at 15:20
  • 1
    The AlarmReceiver will maintain the Context. Your PendingIntent will be received from a BroadcastReceiver that will implement the `onReceive(Context context, Intent intent)` method. So you can use that context for starting the Activity (with flag FLAG_ACTIVITY_NEW_TASK) – GVillani82 May 14 '15 at 15:22

0 Answers0