티스토리 뷰

안드로이드/프로그래밍

서비스

에어버스 2011. 1. 2. 18:01

서비스를 구현할 class(MyService) 는 Service 를 상속받아 아래와 같이 구현한다.

public class MyService extends Service {
   @Override
 public IBinder onBind(Intent arg0) {
  // TODO Auto-generated method stub
  return null;
 }

 @Override
 public void onCreate() {
  // TODO Auto-generated method stub
  super.onCreate();
  Log.i(DEBUG_TAG, "Myservice-onCreate()" ); // 서비스 생성될때 수행할 동작
 }

 @Override
 public void onDestroy() {
  // TODO Auto-generated method stub
  Log.i(DEBUG_TAG, "Myservice-onDestroy()" ); // 서비스 종료할때 수행할 동작
  super.onDestroy();
 }

 @Override
 public void onStart(Intent intent, int startId) {
  // TODO Auto-generated method stub
  Log.i(DEBUG_TAG, "Myservice-onStart()"); // 서비스 시작할때 수행할 동작
 }}

 서비스 이용하기
Intent intentMyService = new Intent(ServiceDemo.this, MyService.class);
android.content.ComponentName service = startService(intetntMyService);// 서비스 시작
....
stopService(intentMyService); // 서비스 종료

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28