안드로이드 개발 질문/답변
(글 수 45,052)
public class BackgroundService extends Service{
private NotificationManager notificationMgr;
private Thread thr;
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
notificationMgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
displayNotificationMessage("백그라운드 서비스 시작");
thr = new Thread(null, new ServiceWorker(), "BackgroundService");
thr.start();
}
class ServiceWorker implements Runnable
{
public void run()
{
// TODO : 여기에 백그라운드 처리 넣기
Log.i("info", "서비스 실행중");
// 처리 완료되면 서비스 종료
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
//return super.onStartCommand(intent, flags, startId);
return Service.START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
if(thr.isAlive()) thr.interrupt();
displayNotificationMessage("백그라운드 서비스 종료");
super.onDestroy();
}
private void displayNotificationMessage(String message)
{
Notification notification = new Notification(R.drawable.note, message, System.currentTimeMillis());
PendingIntent conIntent = PendingIntent.getActivity(this, 0, new Intent(this, ServiceTest_2.class), 0); notification.setLatestEventInfo(this, "백그라운드 서비스", message, conIntent); notificationMgr.notify(R.id.app_notification_id, notification); } }
서비스 시작시 아이콘과 텍스트를 출력해주고 서비스 종료시 역시 아이콘과 텍스트를 출력해주고 있습니다.
그런데 제가 원하는 것은 서비스가 종료되고 난 다음에는 상태바에 아이콘이 사라져야 하는데 아이콘이 사라지지 않고
남아 있습니다. notificationMgr 변수를 cancel도 시켜보고 했지만 아이콘이 사라지지 않는데 어디를 고쳐야 하는지요?
2011.07.13 15:17:48
어랄 다시 읽어보니 제가 단 댓글이 병맛이네여;; ㅎㅎㅎ;; (제대로 안읽어서 죄송;)
notificationMgr.cancel(R.id.app_notification_id) ; 이거인데다가
cancel도 해보셧다고 하니 한가지 질문드려보고 싶은게
onDestroy()가 제대로 호출되나요???




displayNotificationMessage(String message) 함수에서
메시지가 들어오면 어떤 메세지이든 아무 상관없이 notify 만 실행하는군요.
없애실려면
notification.cancel(R.id.app_notification_id) ;
이거 쓰셔야합니다아