2013-04-10 3 views
1

AndroidManifest.xml에서 "android.intent.action.BOOT_COMPLETED"이벤트에 BroadcastReceiver를 등록합니다. 이것은 Android 장치가 부팅 할 때마다 서비스를 시작합니다.앱 시작시 Android 시작 시스템 서비스

... 
     <receiver android:name="MySystemScheduleReceiver" > 
      <intent-filter> 
       <action android:name="android.intent.action.BOOT_COMPLETED" /> 
      </intent-filter> 
     </receiver> 
... 

그러나, 나는 시스템 서비스는 장치를 재부팅 할 필요없이 바로 응용 프로그램 설치 후 시작하고 싶습니다.

앱을 시작할 때 사용할 수있는 시스템 이벤트가 있습니까? 또는 맞춤 이벤트를 설정해야합니까?

나는

... 
     <receiver android:name="MySystemScheduleReceiver" > 
      <intent-filter> 
       <action android:name="android.intent.action.BOOT_COMPLETED" /> 
       <action android:name="com.myapp.StartSysService" /> 
      </intent-filter> 
     </receiver> 
... 

같은 내 매니페스트 파일을 수정해야하고

... 
     Intent intent = new Intent(); 
     intent.setAction("com.myapp.StartSysService"); 
     sendBroadcast(intent); 
... 

그렇다면, 내가 방법을 사용한다

같은 내 주요 활동에서 서비스를 시작? (에서 onCreate, onResume ...)

감사

+0

를 추가 펌웨어가 아닌 앱의 일부. 귀하가 말하는 내용에 대해 ** 완전하고 ** 정확하도록 ** 질문을 편집하십시오. – CommonsWare

+0

GUI 작업이 있습니까? 만약 그렇다면, 당신은 ** onCreate ** 메소드에서 당신의 활동으로부터 서비스를 시작할 수 있습니다 :'Intent service = new Intent(); service.setAction ("com.myapp.MyService"); context.startService (service); ' –

+0

sendBroadcast 호출을 onCreate (기본 GUI 작업)에 배치했는데 제대로 작동하는 것 같습니다. 감사. – user1936810

답변

4

당신은에서 onCreate() 콜백이있는 응용 프로그램을 서브 클래 싱 할 수 있습니다. 서비스를 시작할 수 있습니다. 시스템 서비스는 - 매니페스트의 <application> 태그에

public class MyApplication extends Application { 
    public void onCreate() { 
     // start your service 
    } 
} 

, "나는 시스템 서비스는 장치를 재부팅 할 필요없이 바로 응용 프로그램 설치 후 시작하고 싶습니다, 그러나" android:name="MyApplication"