2012-03-20 3 views
2

의 부족에 의해 살해 될 때이 onStartCommand() 작동하지 않습니다안드로이드 (서비스 및 PhoneStateListener) - 서비스 않습니다 다시 시작하지만 응용 프로그램이 작업 관리자, 킬러 또는 메모리

@Override 
public int onStartCommand(Intent intent, int flags, int startId) { 
    // Notification creation code 

    telMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 
    telMgr.listen(new PSL(), PhoneStateListener.LISTEN_CALL_STATE); 

    return super.onStartCommand(intent, flags, startId); 
} 

과 (서비스 클래스에서) PhoneStateListener 클래스

public class PSL extends PhoneStateListener { 
    public void onCallStateChanged(int state, String incomingNum) { 
     switch(state) { 
     case TelephonyManager.CALL_STATE_IDLE: 
     case TelephonyManager.CALL_STATE_OFFHOOK: 
      //Work1 
      break; 
     case TelephonyManager.CALL_STATE_RINGING: 
      //Work2 
      break; 
     } 
    } 
} 

둘 다 동일한 된 .java 파일에

나는 하나 개의 서비스 클래스에이 코드가 있습니다.

주 활동에서 startService()으로 전화하면 제대로 작동합니다. 하지만 내 앱이 작업 관리자, Killer에 의해 또는 기기의 메모리 부족으로 자동 종료되면 서비스가 다시 시작되지만 작동하지 않습니다. 내가 Setting - Application - Running으로 갈 때, 살해 당하기 전후에 프로세스 1과 서비스 1을 보여줍니다. 그러나 죽인 후에는 메모리 점유율이 1/10이됩니다. startForeground()를 내 알림으로 쉽게 종료하지 않으려 고 시도했습니다. 작동하지 않았습니다. (알림을 표시하지 않음) 또한 onStartCommand() : START_STICKY, START_REDELIVER_INTENT의 복귀를 시도했습니다. 동일한 결과가 완전히 다시 시작하거나 죽이지 않도록 할 수있는 방법이 있습니까?

답변

0

나는 startForeground()에 의해 그것을 해결

내가 알림

Notification.FLAG_FOREGROUND_SERVICE을 사용하지 않았기 때문에 그것은 작동하지 않았다
관련 문제