本文介绍了Android进程是杀死应用程序的严重错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是确切的错误

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

这是场景它基本上是一个步跟踪器

Here is the scenarioIt is basically a step tracker

但是从任务列表中删除该应用程序时,出现此错误.

But when the app is removed from task list I am getting this error.

这是代码.

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);
    }


}

这是联想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

推荐答案

更改onbind方法,该方法将null返回

Change your onbind method which returns null to

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

如果无法正常运行,请再次运行

and run again if not working please see the below links

为什么即使我使用了START_NOT_STICKY,杀死进程后我的Android服务也会重新启动吗?

在下面的链接中,一个正在使用相同的过程来获取警报服务,而其他服务则在后台也请查看

In the below link, one is using the same procedure to get alarm services and the others services in back ground check this out also

服务崩溃并重新启动

这篇关于Android进程是杀死应用程序的严重错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 05:28