2013-08-05 2 views
0

장치가 부팅을 완료했을 때 Service이 시작되지 않는 이유를 알고 싶습니다. 장치가 부팅 될 때 Service이 시작되지만, 응용 프로그램을 먼저 열어야하기 때문에 시작되지 않기를 바랍니다. 여기부팅시 서비스 시작이 올바르게 작동하지 않음

내 코드는 지금까지 있습니다 : BootService이

public class BootService extends BroadcastReceiver{ 

    Intent intent; 

    @Override 
    public void onReceive(Context context, Intent intent2) { 
     intent = new Intent(context, MyService.class); 
     context.startService(intent); 
    } 

} 
+1

http://stackoverflow.com/q/8531926/726863 –

+0

http://www.vogella.com/articles/AndroidServices/#tutorial_ownservice –

+0

나는 방송에 println 메소드를 넣어 내 특정 문제 –

답변

1

라고? 자바 파일에 다음 줄을 추가

1)

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 

2)

<receiver android:name="BootService" > 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
     </intent-filter> 
    </receiver> 
+0

있습니다! 그러나 그것은 작동하지 않습니다 :-( –

+0

then intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK);를 추가하십시오 이것은 수신자로부터의 통화 활동 – djodjo

0

: 부팅 당신이 당신의 매니페스트에 추가 할 필요가 완료 될 때 BootService를 들어

가 트리거 할

intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);

그러면 작동합니다.

0

신청서에 android.intent.action.BOOT_COMPLETED 인 텐트를 수신하려면 먼저 기기에서 Activity을 실행해야합니다.

모범 사례 또는 앱 소개를 시도해보십시오. 그 외에는


BroadcastReceiver에와 Service에 로그 문을 가하고의 생각은 좋은 것입니다.

또한 모두 djodjo's suggestions을 따라 갔는지 확인하십시오.

관련 문제