我正在从警报中调用服务。我得到实例化异常
public class OnAlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// PullPendingRequests.acquireStaticLock(context);
Toast.makeText(context, "Don't panik but your time is up!!!!.", Toast.LENGTH_LONG).show();
Log.d("Taxeeta:PullPendingRequets", "CallService Location");
context.startService(new Intent(context, DriverService.class));
}
}
我的服务代码
public class DriverService extends Service {
private String identityHash;
private WakeLock mWakeLock;
public DriverService(String identityHash) {
this.identityHash = identityHash;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
private void handleIntent(Intent intent) {
}
private class PollTask extends AsyncTask<Void, Void, Void> {
//MY STUFF HERE
}
@Override
public void onStart(Intent intent, int startId) {
handleIntent(intent);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
handleIntent(intent);
return START_NOT_STICKY;
}
public void onDestroy() {
super.onDestroy();
mWakeLock.release();
}
}
编辑:我的清单代码
<service
android:name=".DriverService"
android:enabled="true"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar" />
<receiver
android:name="com.taxeeta.support.OnAlarmReceiver"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.NOTIFY" />
</intent-filter>
</receiver>
编辑:下面的例外
10-10 12:56:09.550: E/AndroidRuntime(11886): FATAL EXCEPTION: main
10-10 12:56:09.550: E/AndroidRuntime(11886): java.lang.RuntimeException: Unable to instantiate service com.taxeeta.DriverService: java.lang.InstantiationException: com.taxeeta.DriverService
10-10 12:56:09.550: E/AndroidRuntime(11886): at android.app.ActivityThread.handleCreateService(ActivityThread.java:1933)
10-10 12:56:09.550: E/AndroidRuntime(11886): at android.app.ActivityThread.access$2500(ActivityThread.java:117)
10-10 12:56:09.550: E/AndroidRuntime(11886): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:989)
10-10 12:56:09.550: E/AndroidRuntime(11886): at android.os.Handler.dispatchMessage(Handler.java:99)
10-10 12:56:09.550: E/AndroidRuntime(11886): at android.os.Looper.loop(Looper.java:130)
10-10 12:56:09.550: E/AndroidRuntime(11886): at android.app.ActivityThread.main(ActivityThread.java:3687)
10-10 12:56:09.550: E/AndroidRuntime(11886): at java.lang.reflect.Method.invokeNative(Native Method)
10-10 12:56:09.550: E/AndroidRuntime(11886): at java.lang.reflect.Method.invoke(Method.java:507)
10-10 12:56:09.550: E/AndroidRuntime(11886): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
10-10 12:56:09.550: E/AndroidRuntime(11886): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
10-10 12:56:09.550: E/AndroidRuntime(11886): at dalvik.system.NativeStart.main(Native Method)
10-10 12:56:09.550: E/AndroidRuntime(11886): Caused by: java.lang.InstantiationException: com.taxeeta.DriverService
10-10 12:56:09.550: E/AndroidRuntime(11886): at java.lang.Class.newInstanceImpl(Native Method)
10-10 12:56:09.550: E/AndroidRuntime(11886): at java.lang.Class.newInstance(Class.java:1409)
10-10 12:56:09.550: E/AndroidRuntime(11886): at android.app.ActivityThread.handleCreateService(ActivityThread.java:1930)
10-10 12:56:09.550: E/AndroidRuntime(11886): ... 10 more