fizgig
fizgig

Reputation: 312

Android - run a prompt on a schedule

I have a request that an application prompt the user to update (if the policy manager site says an update is available), and if they decline, prompt them again in N minutes. I have seen similar questions asked but when I tried to implement the code using handlers or timers, the activity is out of scope or a crash happens that I can't quite figure out, the class I am using requires an application context and an activity to get out various string variables and do tasks.

So I would like to generalize the question as maybe I am thinking about it the wrong way:

What is the best way to schedule a prompt for an update that can either be cancelled and return the user to the activity they were on (and then scheduled run again in N minutes), or direct the user to a web site?

Upvotes: 0

Views: 88

Answers (1)

IncrediApp
IncrediApp

Reputation: 10353

You should be using an AlarmManager with a PendingIntent and a BroadcastReceiver. You set the time with the alarm manager and give it a PendingIntent which you get by using the PendingIntent.getBroadcast method. 1 of the params you give this method is the BroadcastReceiver class which would receive a call when the time is up where you can do pretty much anything you'd like, which would probably be starting a new activity in your case.

Upvotes: 1

Related Questions