gpt4 book ai didi

Android进程在杀死应用程序时出现错误

转载 作者:太空狗 更新时间:2023-10-29 14:40:44 28 4
gpt4 key购买 nike

这是准确的错误

02-08 12:36:43.490 3479-4980/? W/ActivityManager: Scheduling restart of crashed service com.wfl/.StepTrackerShakeDetectorService in 1000ms

02-08 12:36:44.494 3479-3513/? W/ActivityManager: Unable to launch app com.wfl/10139 for service Intent { cmp=com.wfl/.StepTrackerShakeDetectorService }: process is bad

场景如下它基本上是一个计步器

StepTrackerShakeDetectorService is implemented to restart automatically when app is destroyed using START_STICKY

但是当应用程序从任务列表中删除时,我收到此错误。

这是代码。

public class StepTrackerShakeDetectorService extends Service {

private SensorManager mSensorManager;
private StepTrackerShakeDetector mShakeDetector;
private Sensor step_counter_sensor;
private Sensor step_detector_sensor;
private Sensor step_accelerometer;

@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onCreate() {

registerDetector();
}


private void registerDetector() {

mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

step_counter_sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
step_detector_sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
step_accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

if (step_counter_sensor != null) // sensor not supported
{
mShakeDetector = new StepTrackerShakeDetector(Sensor.TYPE_STEP_COUNTER);
mSensorManager.registerListener(mShakeDetector, step_counter_sensor, SensorManager.SENSOR_DELAY_FASTEST);
} else if (step_accelerometer != null) {

mShakeDetector = new StepTrackerShakeDetector(Sensor.TYPE_ACCELEROMETER);
mSensorManager.registerListener(mShakeDetector, step_accelerometer, SensorManager.SENSOR_DELAY_FASTEST);
}


mShakeDetector.setOnShakeListener(new StepTrackerShakeDetector.OnShakeListener() {

@Override
public void onShake(int count) {
//Code to calculate steps
}
});
}

private void unregisterDetector() {
mSensorManager.unregisterListener(mShakeDetector);
}

@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}

@Override
public void onDestroy() {
unregisterDetector();
super.onDestroy();
}

@Override
public void onTaskRemoved(Intent rootIntent) {
super.onTaskRemoved(rootIntent);
Intent intent = new Intent(getApplicationContext(), StepTrackerShakeDetectorService.class);
PendingIntent pendingIntent = PendingIntent.getService(this, 1, intent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime() + 2000, pendingIntent);
}


}

这是lenovo phab 2的错误

02-13 11:42:12.211 975-1964/? W/ActivityManager: Scheduling restart of crashed service com.wfl/.StepTrackerShakeDetectorService in 1000ms
02-13 11:42:12.213 975-1964/? I/ActivityManager: Force stopping service ServiceRecord{7a45ff2 u0 com.wfl/.StepTrackerShakeDetectorService}
02-13 11:42:12.214 975-1964/? V/ActivityManager: Broadcast: Intent { act=android.intent.action.PACKAGE_RESTARTED dat=package:com.wfl flg=0x10 (has extras) } ordered=false userid=0 callerApp=null
02-13 11:42:12.216 975-2003/? W/ActivityManager: Spurious death for ProcessRecord{2325a63 0:com.wfl/u0a146}, curProc for 30626: null
02-13 11:42:12.790 2342-2361/? D/GasService: FG app changed: from com.wfl to

最佳答案

将这一行放在 onTaskRemoved 中函数的末尾

        super.onTaskRemoved(rootIntent);

关于Android进程在杀死应用程序时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48679603/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com