开发者

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 differ开发者_开发技巧ent?


This may help: http://developer.android.com/reference/android/app/AlarmManager.html


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜