代码之家  ›  专栏  ›  技术社区  ›  TLindig

Android:为什么我在完全限定的类名中得到一个斜线和“WARN/ActivityManager(52):无法启动服务意图”

  •  1
  • TLindig  · 技术社区  · 15 年前

    http://www.helloandroid.com/files/xmaswidget/android_howto-hellowidget.pdf

    但是,如果我试图用服务(该教程中的第二种方式)启动示例,我在DDMS的LogCat中得到了以下错误消息:

    WARN/ActivityManager(52): Unable to start service Intent { cmp=de.tlindig.android/.HelloWidget$UpdateService }: not found
    

    我不明白的是,包名后面的斜杠(“/”)来自哪里。

    @Override
    

    public void onUpdate(上下文上下文,AppWidgetManager AppWidgetManager, int[]appWidgetIds){

      Log.d("HelloWidget.onUpdate", "UpdateService.class is: " + UpdateService.class);
      Intent intent = new Intent(context, UpdateService.class);
      context.startService(intent);
     }
    

    所以我在LogCat中得到了以下输出:

    DEBUG/HelloWidget.onUpdate(320): UpdateService.class is: class de.tlindig.android.HelloWidget$UpdateService
    WARN/ActivityManager(52): Unable to start service Intent { cmp=de.tlindig.android/.HelloWidget$UpdateService }: not found
    

    有人知道我做错了什么吗?

    谢谢你的帮助。

    1 回复  |  直到 15 年前
        1
  •  2
  •   TLindig    15 年前

    我自己找到了解决办法。

    每个服务都需要清单文件中的条目。我的情况是这样的:

    <service android:name=".HelloWidget$UpdateService" />
    

    就这样。现在找到并启动了服务。