我正在使用 Intent Service-Myintentservice.java。在那我已经放置了一个警报管理器以在指定时间启动相同的意图服务..当我创建登录时,它以毫秒为单位连续运行,直到它停止后达到开始时间。
代码:
public class Myintentservice extends IntentService{
@Override
protected void onHandleIntent(Intent intent) {
if(within start and end time){
.....Do the required task....
}
else
{
am1=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent locup=new Intent(this,Myintentservice.class);
locupIntent=PendingIntent.getService(this, 0,locup, PendingIntent.FLAG_UPDATE_CURRENT);
Log.i("locup", "postinginterval-->"+Integer.toString(point));
Log.i("ctalarm", "trigger time-->"+Long.toString(hms.getTimeInMillis()));
am1.setRepeating(AlarmManager.RTC_WAKEUP, hms.getTimeInMillis(), point, locupIntent);
}
}
}
我在 onHandleIntent 方法中包含了 if..else 语句。如果开始时间和结束时间在当前时间之间 IF 部分将执行,否则转到 ELSE 部分并在到达开始时间时再次执行..已将开始时间传递给 hms .getTimeInMillis() 设置重复警报..
服务在指定时间开始和结束,但我的问题是服务或警报管理器是否运行我在上面创建的日志直到开始时间到达?是否有可能停止该服务或警报并在指定时间开始..?