【发布时间】:2018-12-21 21:27:56
【问题描述】:
我有一个需要在后台永久运行的服务,但是一旦活动关闭,它创建的 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 运行时启动?
【问题讨论】:
标签: java android-studio android-intent background-process