如何禁用Android服务几个小时并重新启动它?
daybtn.setOnClickListener(new View.OnClickListener() {
//hide for 2 hr
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(c, "Service disabled for 5min", Toast.LENGTH_LONG).show();
Intent i = new Intent(context, Service.class);
context.stopService(i);
new Handler().postDelayed(new Runnable() {
public void run () {
// Do delayed stuff!
Intent intent2 = new Intent(c, Service.class);
c.startService(intent2);
}
}, 300000L); //5 min delay
}
});
上面的代码工作5分钟,但如果我尝试执行相同的1小时或更长时间(3600000L),那么它不起作用。我如何实现这一目的超过一个小时或两个小时?谢谢