我有一个需要在后台永久运行的服务,但是一旦活动关闭,它创建的IntentService也会立即运行:public class CAS extends IntentService { public CAS() { super("CAS"); } Sensor accelerometer; SensorManager sensorManager; CA cA= new CA(); @Override protected void onHandleIntent(@Nullable Intent intent) { sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); sensorManager.registerListener(cA, accelerometer, SensorManager.SENSOR_DELAY_FASTEST); LocationManager locationManager = GlobalFunctions.LocationLibrary.getLocationManager(this); cA.start(this, locationManager); }}我如何才能使此类在后台无限期地运行,甚至在Android运行时也可以启动?
添加回答
举报
0/150
提交
取消