【发布时间】:2013-12-06 06:53:57
【问题描述】:
我正在尝试构建一个远程服务,我可以将其绑定到将经常使用和创建的活动。我认为这是处理我想要完成的事情的最佳方法。我一直收到这个错误。
无法启动服务 Intent { act=com.services.OverheadService } U=0:未找到
我认为我的清单可能有问题?但是我没看到什么,我的manifest会在下面相关代码的底部。
这是我活动中 onCreate() 中的调用:
// TESTING SERVICE IMPLMENTATION TODO
Intent serviceIntent = new Intent("com.services.OverheadService");
boolean ok = this.bindService(serviceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
Log.v("ok", String.valueOf(ok));
这是连接方法:
/** SERVICE IMPLEMENTATION TESTING **/
private ServiceConnection mServiceConnection = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
// get instance of the aidl binder
mRemoteService = IRemoteService.Stub.asInterface(service);
try {
String message = mRemoteService.sayHello("Mina");
Log.v("message", message);
} catch (RemoteException e) {
Log.e("RemoteException", e.toString());
}
}
};
这里是服务类:
package com.services;
import com.services.IRemoteService.Stub;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
public class OverheadService extends Service {
@Override
public IBinder onBind(Intent arg0) {
return mBinder;
}
// implementation of the aidl interface
private final IRemoteService.Stub mBinder = new Stub() {
@Override
public String sayHello(String message) throws RemoteException {
return "Hello " + message;
}
};
}
正在设置服务的AndroidManifest:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<service
android:name="com.services.OverheadService"
android:enabled="true"
android:icon="@drawable/failed_load" >
<!--
intent-filter>
<action android:name="com.cdkdevelopment.BaseActivity" />
</intent-filter>
-->
</service>
【问题讨论】:
标签: android android-intent android-service