[英]Run an IntentService without an Activity
我有一個需要在后台永久運行的服務,但是一旦活動關閉,它創建的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運行時啟動?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.