마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

부팅시 서비스 실행에 대해서 문의

0 추천
브로드캐스트

public class RestartService extends BroadcastReceiver {

 @Override
 public void onReceive(Context context, Intent intent) {
  // 폰 재부팅시 서비스 등록
  if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
   Intent i = new Intent(context, ServiceClass.class);
   context.startService(i);
  }
  // 서비스 죽일때 알람으로 다시 서비스 등록
  if (intent.getAction().equals("ACTION.RESTART.ServiceClass")) {
   Intent i = new Intent(context, ServiceClass.class);
   context.startService(i);
  }
 }
}

 

매니페스트

 <!-- 부팅 앱 자동 실행 매니퍼스트 파일 권한 등록-->
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"

 

 <receiver android:name="health.all.water_bottle.RestartService"
            android:enabled="true"
            android:exported="false"
            android:label="RestartService"
            android:process=":remote" >
            <intent-filter>
                <action android:name="ACTION.RESTART.ServiceClass" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

 

서비스

 

@Override
 public int onStartCommand(Intent intent, int flags, int startId) {
  Log.i(TAG, " +++ onStartCommand Service +++");
 
  if(intent.getStringExtra("finish") != null){
   stopForeground(true);
   stopSelf();
   mBluetoothAdapter.disable();
   System.exit(0);
  }else if(intent.getStringExtra("phone") != null){
   inputnumber = intent.getStringExtra("phone");
   Log.i(TAG, "인텐드로 넘어 온 전화번호  : " + inputnumber);
   showNotification();
  }
  return Service.START_REDELIVER_INTENT; //전화 번호 값 유지하기 위해서
 }

 

재부팅시 오류가 떠요.. 로그캣으로 원인을 찾고 싶은데 부팅시에는 로그캣이 안되서 원인을 찾을 수가 없네요

어떻게 처리해야하나요?? 알려주시면 감사하겠습니다.

부탁드립니다.
쿠쿠부다스 (6,470 포인트) 님이 2016년 2월 4일 질문

1개의 답변

0 추천
브로드캐스트리시버에다가

 

    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); <<--추가해보세여
sadeva (21,550 포인트) 님이 2016년 2월 4일 답변
해봤는데 그래도 오류가 뜨네요 ㅠㅠ
근데  FLAG_ACTIVITY_NEW_TASK는 Activity 클래스 실행시킬때만 쓰는것이 아닌가요??
...