English 中文(简体)
安排在安的安康附近时间执行任务的最佳方式是什么?
原标题:What is the best way to schedule a task guaranteed to run at near-scheduled time in Android?

I have been using Timer & TimerTask with Pseudocode:-

 samplingTask = new TimerTask() {

   public void run() {
     collectSample();
   }

 };

 timer.schedule(samplingTask, 60*1000, 60*1000); //1 min

申请时间很长(如15分钟,没有听觉,屏幕倒塌)。 在安排这项任务之后,我锁定了屏幕,电话正在启用(传感器管理人为摄像仪启用)。 因此,理想的情况是,这项任务应每分钟执行一次。 然而,在原木中,我看到,定时仪的运行时间仅为第5分钟、第9分钟和第12分钟。

FINER: (13,Timer-0,Workout)In Timertask, nth minute=5
FINER: (13,Timer-0,Workout)In Timertask, nth minute=9
FINER: (13,Timer-0,Workout)In Timertask, nth minute=12

我的要求是有时间性强的抽样,可接受的延迟范围为几秒(1-5秒)。 看来,如果该装置是睡觉的,那么,时间器就会赶上,执行预定的任务。 没有任何其他选择。 文件说,AlarmManager和Handler可以使用。 我认为,最好是利用AlarmManager,根据某些系统警报进行单一射击。 是否有东西是我所不知的,还是实现这一功能的一些替代办法。

问题回答

您可以使用<条码>AlarmManager——它有机会软弱化装置并多次执行某些任务。

我并不确切知道,但很抱歉,当用户开脱屏幕时,所有任务都会消失,在装置睡觉时可能不做任何密码。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签