2011-06-23 8 views
0

は、私は私のアプリのサービスには、以下を経由して通知を開始すると言う:Android - サービスの通知を閉じる方法は、startForegroundによって開始されましたか?

notification = new Notification(R.drawable.icon, getText(R.string.app_name), System.currentTimeMillis()); 
     Intent notificationIntent = new Intent(this, mainActivity.class); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); 
     initService.notification.setLatestEventInfo(this, getText(R.string.app_name), "ibike rider", pendingIntent); 

     startForeground(ONGOING_NOTIFICATION, notification); 

は、どのように私はおよそshutting down/cancellingこのサービスを行くだろうか?他の活動でこれを行うことは可能でしょうか?

ありがとうございました。

答えて

1

startServiceコールによって開始され、stopServiceコールによって停止された任意の「開始済み」サービス(バックグラウンドサービスまたはフォアグラウンドサービスであるかどうかに関わらず)。

あなたのサービスは、そのonStartCommand実装で複数の要求を処理できるなら、あなたはstartServiceの追加の呼び出しによってそのライフサイクルを管理することができます。たとえば

LocationService.java - GTalkSMS

+0

素晴らしい回答、ありがとう! – JDS

関連する問題