Stelios
Stelios

Reputation: 271

Call a specific action in certain time in Android

What I want is 5 minutes after I open the application do a specific work.

I am not sure what I suppose to do.Should I create an AsyncTask in onCreate method of my main activity or a thread? Or should i do something completely different?

Upvotes: 0

Views: 2153

Answers (3)

advantej
advantej

Reputation: 20325

Your question is a combined question asking how (way) to perform a task as well as how to schedule it.

  1. Decide what is the task you want to perform. If its a long running task, use either AsyncTask or IntentService
  2. To schedule the task you can either use Hander postDelayed, Timer or AlarmManager. My pref. would be a one-time AlarmManager - Once registered, even if you app is not running, the callback will be triggered.

Upvotes: 1

Snicolas
Snicolas

Reputation: 38168

You could use a Handler :

 new Handler().postDelayed(new Runnable() { public void run() {
           //your delayed action here, on UI Thread if needed
      }
   }, 1000 * 60 * 5 );

Regards, Stéphane

Upvotes: 0

Related Questions