【问题标题】:Android Service: Unable to start service intent { act=edu.darts.neuromobi.TestService }: not foundAndroid 服务:无法启动服务意图 { act=edu.darts.neuromobi.TestService }:未找到
【发布时间】:2011-12-05 22:00:48
【问题描述】:

我遇到了其他人遇到的同样问题,但我的代码无法正常工作。

我必须使用 java 类,Test.java 和 TestService.java,当我尝试启动服务或绑定服务时,我总是得到上面列出的错误。我已经尝试过here 中推荐的标准解决方案,但没有奏效。我将尝试重命名 java 文件并启动一个新项目,看看它是否如here 中所述工作。

然后我看到 Vogella 的 link 我必须在设备上注册一个谷歌用户。这是我的问题还是我混淆了错误(也许'intent.REGISTER'指的是别的东西)。

对此的任何建议将不胜感激。

4.3。注册您的应用程序

运行您的应用程序,维护您的注册用户并按 按钮。检查 LogCat 以获取注册 ID。

如果您看到以下消息:

" 无法启动服务 Intent {act=com.google.android.c2dm.intent.REGISTER ... }:未找到”

我在手机和模拟器上都试过了。

权限:

<application android:icon="@drawable/gyroscopic" android:label="@string/app_name">
...
<activity android:name="Test"></activity>

<service android:name="TestService"></service>  
....
</application>

【问题讨论】:

  • 感谢您解决我的问题@Vimal
  • WC,我们在这里合作和互相帮助:)

标签: android service android-intent


【解决方案1】:

尝试为您的服务使用整个包代码,这就是我一直在做的事情,并且到目前为止它一直有效。

<service
    android:enabled="true"
    android:name="com.mobowski.appfrag.service.MusicService" >
</service>

编辑以启动/绑定到服务。

我通常这样做:

启动服务

// This is in the onCreate of my main screen, but this would work in a button
startService(
            new Intent(this, Service.class));

在服务本身中

绑定到服务时会用到这个

// Field of service
private final IBinder mBinder = new MyBinder(); 

// We return the binder class upon a call of bindService
    @Override
    public IBinder onBind(Intent arg0) {
        return mBinder;
    }

    public class MyBinder extends Binder {
        public MusicService getService() {
            return MusicService.this;
        }
    }

绑定到服务

为此,我使用了我曾经从一个示例中提取的几段代码,但到目前为止它们从未让我失望。

private ServiceConnection mConnection = new ServiceConnection() {

        public void onServiceConnected(ComponentName className, IBinder binder) {
            s = ((MusicService.MyBinder) binder).getService();
            Toast.makeText(this, "Connected", Toast.LENGTH_SHORT)
                    .show();
            // Little Toast to make sure we connected

        }

        public void onServiceDisconnected(ComponentName className) {
            s = null;
        }
    };

    void doBindService() {
        bindService(
            new Intent(this,
                    MusicService.class), mConnection,
            Context.BIND_AUTO_CREATE);

    }

【讨论】:

  • 就像我上面说的,我读过很多相关的帖子(但我并不是说我都读过——有很多)提出了同样的问题,但事实并非如此工作(这是我清单中的内容):... &lt;service android:enabled="true" android:name=".AccelerometerService"&gt;&lt;/service&gt; &lt;activity android:name="TremCam"&gt;&lt;/activity&gt; &lt;/application&gt;
  • 问题。您如何尝试启动/绑定到服务?
  • 服务绑定由:Intent i = new Intent(AccelerometerService.class.getName()); bindService(i, _connection, Context.BIND_AUTO_CREATE); _isBound = true;
  • 启动服务(点击按钮时)://Intent i = new Intent(AccelerometerService.class.getName()); Intent i = new Intent("edu.nd.bitstorm.AccelerometerService"); this.startService(i);
【解决方案2】:

您需要以某种形式在 name 属性中提供命名空间:

<service android:name="edu.darts.neuromobi.TestService"></service>

或者可能:

<service android:name=".TestService"></service>

【讨论】:

  • 感谢@Vimal 修复我的帖子,下次我会这样做。
  • 我在许多其他相关帖子中看到了您的建议,但我得到了相同的结果!我什至尝试只使用服务和活动(使用按钮启动或绑定到服务)并将它们放在一个新项目中,并使用不同的文件名具有相同的结果。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-27
  • 1970-01-01
  • 2012-08-20
  • 1970-01-01
相关资源
最近更新 更多