myDataBsae で値が見つかったときに通知するインテントサービスがありますが、データが null の場合は通知しないでください。
- Intentservice で 50 秒ごとに myDataBase のコンテンツをチェックするにはどうすればよいですか (AlarmManager を使用しましたが、データベース = null にもかかわらず、サービスから 50 秒ごとに通知されます)。
- トリガーするときに、インテントサービスを個別にスレッドで動作させたい
私のサービスは:
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);
}
}
}