2015-07-10 45 views
2

我的应用程序有一个扫描蓝牙设备的服务。 此扫描由U.I.控制。 一旦开启,它会无限期地继续,但需要隐式间歇以节省电量。我该怎么办? : 1)使用sleep()的while循环的AsyncTask; 2)ScheduledExecutorService 3)Handler 4)Alarm + Bound Service +广播接收机 还是什么? P.S. - 间隔时间可能从几秒到1小时不等。如何在android中以小间隔定期运行后台服务?

+0

使用setInexactRepeating使用[Alarm Manager](http://developer.android.com/reference/android/app/AlarmManager.html#setInexactRepeating(int,%20long,%20long,%20android.app.PendingIntent)) (......) –

回答

0

它应该在应用程序在后台时继续扫描吗?如果是这样,请使用已启动服务的警报;如果没有,请在活动中使用处理程序。