Android 如何使Intentservice重复作业?
我有一个intentservice,当在myDataBsae中找到值时通知我,但若数据为null,则不应通知我,所以Android 如何使Intentservice重复作业?,android,Android,我有一个intentservice,当在myDataBsae中找到值时通知我,但若数据为null,则不应通知我,所以 如何使我的Intentservice每50秒检查一次我数据库的内容(我使用AlarmManager,但我的服务每50秒通知我一次,尽管我的数据库=null,) 当我触发intentservice时,我希望它单独工作 我的服务是: public class ShowTimeServer extends IntentService { NotificationManager
public class ShowTimeServer extends IntentService {
NotificationManager nm;
static final int uniqueID=326534;
public ShowTimeServer() {
super("ShowTimeServer");
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see android.app.IntentService#onHandleIntent(android.content.Intent)
*/
@Override
protected void onHandleIntent(Intent arg0) {
// TODO Auto-generated method stub
ShowTimeDB RetrieverDB =new ShowTimeDB(this);
RetrieverDB.open();
String data = RetrieverDB.getShowNotify();
RetrieverDB.close();
if (!(data.equals(null))){
nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent intent=new Intent(this,TodayShow.class);
PendingIntent pi= PendingIntent.getActivity(this, 0, intent, 0 );
CharSequence x=(CharSequence) data;
Notification n=new Notification(R.drawable.ic_launcher,"YOU HAVE SHOW" ,System.currentTimeMillis());
n.setLatestEventInfo(this, "ShowTime", x, pi);
n.defaults=Notification.DEFAULT_ALL;
nm.notify(uniqueID,n);
//pi.cancel();
//nm.cancel(uniqueID);
}
}
}
你的意思是我不能在itI中设置runnable或timer吗?我不明白你指的是什么。请进一步解释。我的意思是我可以使用下面的sach代码并将我的通知代码放入其中***>private TimerTask mTask=new TimerTask(){@Override public void run(){//任何你想要的postDelayed(这个,重复间隔);//清洗并重复…};