【发布时间】:2014-02-17 09:53:33
【问题描述】:
我正在尝试在 android 的服务中建立我的手机和蓝牙卡之间的连接,但我遇到了服务问题。半小时后服务会自动重启。我的目标是让我的服务尽可能长时间地运行。
public void onCreate() {
Log.d("PrinterService", "Service started");
super.onCreate();
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("PrinterService", "Onstart Command");
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter != null) {
if(bluetoothProvider != null)
bluetoothProvider = null;
bluetoothProvider = new BluetoothProvider(getApplicationContext());
bluetoothProvider.startUpdates();
}
return Service.START_STICKY ;
}
@Override
public void onDestroy() {
super.onDestroy();
}
【问题讨论】: