1

myDataBsae で値が見つかったときに通知するインテントサービスがありますが、データが null の場合は通知しないでください。

  1. Intentservice で 50 秒ごとに myDataBase のコンテンツをチェックするにはどうすればよいですか (AlarmManager を使用しましたが、データベース = null にもかかわらず、サービスから 50 秒ごとに通知されます)。
  2. トリガーするときに、インテントサービスを個別にスレッドで動作させたい

私のサービスは:

    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);

    }
}

}
4

1 に答える 1

0
  1. IntentService は、X 秒ごとに処理を行うことを想定していません。このため、他の多くのソリューションがあります。このタスクにサービスを使用することを主張する場合は、それを通常のフォアグラウンド/バックグラウンド サービスにして (ユーザーがアプリを離れたときに実行するかどうかによって異なります)、そこで実行できます。

  2. IntentService は既に別のスレッドで実行されています。そのため、onHandleIntent メソッドで長い操作を行うことができます。

于 2013-03-30T11:41:18.437 に答える