我的问题出在问题标题中,我正在尝试通过登录来启动/绑定一个简单的服务,但它根本不起作用。我想用 Service Connexion 方法来做:
public class testServiceBound extends Service {
/**
* PRIVATE ATTRIBUTES
*/
// log
private static final String TAG = testServiceBound.class.getSimpleName();
private final Binder _binder = new testBinder();
@Override
public void onCreate() {
Log.i(TAG, "onCreate--");
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "onStartCommand--");
return START_STICKY;
}
@Override
public void onDestroy() {
Log.i(TAG, "onDestroy--");
super.onDestroy();
}
@Override
public IBinder onBind(Intent intent) {
Log.i(TAG, "onBind--");
return _binder;
}
public class testBinder extends Binder {
public testServiceBound getServiceInstance() {
Log.i(TAG, "PlayerBinder--getServiceInstance--");
return testServiceBound.this;
}
}
}
在活动中:
private testServiceBound _testService;
public final ServiceConnection _connectionStreamingtest = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder testBinder) {
Log.i(TAG, "onServiceConnected--");
// service
testBinder binder = (testBinder) testBinder;
_testService = binder.getServiceInstance();
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
Log.i(TAG, "onServiceDisconnected--");
_bound = false;
}
};
public void bindToService() {
Log.i(TAG, "bindToService--");
Intent intenttest = new Intent(MainActivity.this, testServiceBound.class);
startService(intenttest);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i(TAG, "onCreate--");
//
// service
bindToService();
}
在清单中:
<service
android:name="com.egdigital.testing.service.testServiceBound"
android:enabled="true"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE" >
</service>
我也试过这个
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
没有错误,没有日志,什么都没有发生..