저는 오랫동안이 문제에 봉착했으며 왜 작동하지 않는지 잘 모릅니다. BroadcastReceiver를 사용하여 장치가 시작될 때 서비스를 시작하려고합니다. 장치가 시작되면 충돌이 발생하고 AndroidManifest에 활동이 등록되었는지 묻습니다.간단한 서비스를 시작하려고 할 때 BroadcastReceiver가 부팅 될 때 오류가 발생합니다.
저는 Genymotion 에뮬레이터를 사용하고 있으며 Eclipse에서 프로젝트를 삭제하는 것은 물론 애플리케이션을 삭제하려고 시도했습니다. 나는 또한 안드로이드 : com.gordon.status.service.StartBackgroundSyncService라는 이름에 전체 이름을 추가하려고 시도했지만 그 중 하나도 작동하지 않습니다.
브로드 캐스트 리시버 :
public class AutostartReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Intent i = new Intent(context, StartBackgroundSyncService.class);
context.startService(i);
}
}
매니페스트 :
<service
android:name="service.StartBackgroundSyncService"
android:enabled="true"
android:exported="false"/>
<service
android:name="service.LinkedInBackgroundService"
android:enabled="true"/>
<receiver android:name="receiver.AutostartReceiver"
android:exported="false"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.QUICKBOOT_POWERON" /> <!-- For some HTC devices -->
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
서비스 (장치가 시작할 때 헬로 표시한다)
public class StartBackgroundSyncService extends Service
{
@Override
public void onCreate()
{
super.onCreate();
System.out.println("HELLO=========================================================");
System.out.println("==============================================================");
}
public int startCommand(Intent intent, int flags, int startId)
{
return super.onStartCommand(intent, flags, startId);
}
@Override
public IBinder onBind(Intent intent)
{
return null;
}
}
로그 캣 :
10-17 20:48:07.438: E/AndroidRuntime(1147): java.lang.RuntimeException: Unable to start receiver receiver.AutostartReceiver: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.gordon.status/service.StartBackgroundSyncService}; have you declared this activity in your AndroidManifest.xml?
10-17 20:48:07.438: E/AndroidRuntime(1147): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2383)
10-17 20:48:07.438: E/AndroidRuntime(1147): at android.app.ActivityThread.access$1500(ActivityThread.java:141)
10-17 20:48:07.438: E/AndroidRuntime(1147): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1310)
10-17 20:48:07.438: E/AndroidRuntime(1147): at android.os.Handler.dispatchMessage(Handler.java:99)
10-17 20:48:07.438: E/AndroidRuntime(1147): at android.os.Looper.loop(Looper.java:137)
10-17 20:48:07.438: E/AndroidRuntime(1147): at android.app.ActivityThread.main(ActivityThread.java:5041)
10-17 20:48:07.438: E/AndroidRuntime(1147): at java.lang.reflect.Method.invokeNative(Native Method)
10-17 20:48:07.438: E/AndroidRuntime(1147): at java.lang.reflect.Method.invoke(Method.java:511)
10-17 20:48:07.438: E/AndroidRuntime(1147): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-17 20:48:07.438: E/AndroidRuntime(1147): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-17 20:48:07.438: E/AndroidRuntime(1147): at dalvik.system.NativeStart.main(Native Method)
10-17 20:48:07.438: E/AndroidRuntime(1147): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.gordon.status/service.StartBackgroundSyncService}; have you declared this activity in your AndroidManifest.xml?
10-17 20:48:07.438: E/AndroidRuntime(1147): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
10-17 20:48:07.438: E/AndroidRuntime(1147): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
10-17 20:48:07.438: E/AndroidRuntime(1147): at android.app.ContextImpl.startActivity(ContextImpl.java:957)
10-17 20:48:07.438: E/AndroidRuntime(1147): at android.app.ContextImpl.startActivity(ContextImpl.java:939)
10-17 20:48:07.438: E/AndroidRuntime(1147): at android.content.ContextWrapper.startActivity(ContextWrapper.java:284)
10-17 20:48:07.438: E/AndroidRuntime(1147): at android.content.ContextWrapper.startActivity(ContextWrapper.java:284)
10-17 20:48:07.438: E/AndroidRuntime(1147): at receiver.AutostartReceiver.onReceive(AutostartReceiver.java:16)
10-17 20:48:07.438: E/AndroidRuntime(1147): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2376)
01,