我正在尝试启动Android中的一个服务(Service):
在
然而,
Log.d("BLE", "Start Service");
Intent gattServiceIntent = new Intent(this, BluetoothLeService.class);
bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE);
startService(gattServiceIntent);
Log.d("BLE", "Service Started");
在
BluetoothLeService
中,我重写了onStartCommand()
函数,这意味着当服务启动时,我会看到log
。public class BluetoothLeService extends Service {
....
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Let it continue running until it is stopped.
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
Log.d("BLE", "onStartCommand");
return START_STICKY;
}
然而,
log
如下:07-14 21:30:23.676: D/BLE(28327): Start Service
07-14 21:30:23.676: D/BLE(28327): Service Started
但是onStartCommand()
从未出现在log
中。我该如何启动服务?