0

앱을 중지하면 서비스가 다시 시작되지 않습니다. 내 실수는 어디 갔지? 내 안드로이드 버전은 7.1.1입니다. 나는 그것을 시도합니다; onStartCommand에서 START_STICKY를 반환했습니다. 이 메소드를 작성합니다.Android 서비스가 다시 시작되지 않습니다.

@Override 
    public void onTaskRemoved(Intent rootIntent){ 
     Log.e("Tem Harita","Service Killed"); 
     if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 
      Intent restartServiceIntent = new Intent(getApplicationContext(), this.getClass()); 
      restartServiceIntent.setPackage(getPackageName()); 


      PendingIntent restartServicePendingIntent = PendingIntent.getService(getApplicationContext(), 1, restartServiceIntent, PendingIntent.FLAG_ONE_SHOT); 
      AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); 
      alarmService.set(
        AlarmManager.ELAPSED_REALTIME, 
        SystemClock.elapsedRealtime() + 3500, 
        restartServicePendingIntent); 
      super.onTaskRemoved(rootIntent); 
     } 

    } 

가끔씩 작동하지 않는 경우가 있습니다. 나는 이유를 모른다. 휴대 전화에

+0

때때로 질문은 조금 불분명 –

+0

네를 위해 동일 할 수

을 최적화하지 말아 클릭 , idk 왜 작동하지 않습니다. 그냥 물어 봤어 :( – KimJoyJoy

답변

0

이동을 은 설정 -> 배터리 -> 배터리 optimisation-> 앱을 클릭 -> 당신은 모든 응용 프로그램