无法启动服务意图;活动中的IntentService

时间:2011-12-26 02:16:48

标签: android android-service

我在Activity中有这样的服务:

public class StudyHalls extends ExpandableListActivity 
implements OnChildClickListener {

@Override 
public void onCreate(Bundle savedInstanceState) {
    ...
}

@Override
public boolean onChildClick(ExpandableListView parent, View view, int groupPosition, int childPosition, long id) {
        ...
}

public class RefreshService extends IntentService {

    public RefreshService() {
        super("RefreshService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        ...
    }

}
}

该服务将通过以下方式在另一项活动中启动:

   startService(new Intent(this, StudyHalls.RefreshService.class));

最后,我将服务添加到清单:

     <service
        android:name="com.ecnu.sei.manuzhang.study.StudyHalls.RefreshService" />

这里有错误信息:

    12-26 10:11:14.093: W/ActivityManager(70): Unable to start service Intent { cmp=com.ecnu.sei.manuzhang.study/.StudyHalls$RefreshService }: not found
编辑:对汤普森来说,我已做出改变以表明:

 <service
        android:name="com.ecnu.sei.manuzhang.study.StudyHalls$RefreshService" />

但我仍然无法使用错误启动服务:

    12-26 10:44:47.943: E/AndroidRuntime(782): FATAL EXCEPTION: main
    12-26 10:44:47.943: E/AndroidRuntime(782): java.lang.RuntimeException: Unable to instantiate service com.ecnu.sei.manuzhang.study.StudyHalls$RefreshService: java.lang.InstantiationException: com.ecnu.sei.manuzhang.study.StudyHalls$RefreshService
    12-26 10:44:47.943: E/AndroidRuntime(782):  at android.app.ActivityThread.handleCreateService(ActivityThread.java:1929) 
    12-26 10:44:47.943: E/AndroidRuntime(782):  at android.app.ActivityThread.access$2500(ActivityThread.java:117)
    12-26 10:44:47.943: E/AndroidRuntime(782):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
    12-26 10:44:47.943: E/AndroidRuntime(782):  at android.os.Handler.dispatchMessage(Handler.java:99)
    12-26 10:44:47.943: E/AndroidRuntime(782):  at android.os.Looper.loop(Looper.java:130)
    12-26 10:44:47.943: E/AndroidRuntime(782):  at android.app.ActivityThread.main(ActivityThread.java:3683)
    12-26 10:44:47.943: E/AndroidRuntime(782):  at java.lang.reflect.Method.invokeNative(Native Method)
    12-26 10:44:47.943: E/AndroidRuntime(782):  at java.lang.reflect.Method.invoke(Method.java:507)
    12-26 10:44:47.943: E/AndroidRuntime(782):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    12-26 10:44:47.943: E/AndroidRuntime(782):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    12-26 10:44:47.943: E/AndroidRuntime(782):  at dalvik.system.NativeStart.main(Native Method)
    12-26 10:44:47.943: E/AndroidRuntime(782): Caused by: java.lang.InstantiationException: com.ecnu.sei.manuzhang.study.StudyHalls$RefreshService
    12-26 10:44:47.943: E/AndroidRuntime(782):  at java.lang.Class.newInstanceImpl(Native Method)
    12-26 10:44:47.943: E/AndroidRuntime(782):  at java.lang.Class.newInstance(Class.java:1409)
    12-26 10:44:47.943: E/AndroidRuntime(782):  at android.app.ActivityThread.handleCreateService(ActivityThread.java:1926)
    12-26 10:44:47.943: E/AndroidRuntime(782):  ... 10 more

1 个答案:

答案 0 :(得分:3)

这是一个内在的阶级。您需要将清单更改为:

<service
    android:name="com.ecnu.sei.manuzhang.study.StudyHalls$RefreshService" />