我有一个关于bindService 的问题。在我的 Activity 中,我有以下代码:
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className,
IBinder service) {
mService = IPrimary.Stub.asInterface(service);
}
public void onServiceDisconnected(ComponentName className) {
mService = null;
}
};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.login);
mApi = new ApiRequest(SIGNIN_METHOD);
boolean isConnected = bindService(new Intent(IPrimary.class.getName()),
mConnection, Context.BIND_AUTO_CREATE);
但是 isConnected 每次都等于 false。
在我的 list 文件中,我有:
<service android:name=".DownloaderService">
<intent-filter>
<action android:name=".IPrimary" />
我不明白这个问题。在logcat中出现:
I/ActivityManager( 52):显示的 Activity com.touristeye.code/.LogIn:485918 毫秒(总计 913151 毫秒)
谢谢
最佳答案
展开 action:name
为 <action>
中的完整值元素。点前缀简写可能仅适用于组件元素(例如 <service>
)。
关于Android 绑定(bind)服务问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2285210/