2017-01-29 2 views
-3

백그라운드 서비스를 개발 중이며 OnDestroy Method에서 서비스를 다시 시작할 인 텐트를 호출했습니다. miui rom (Xiaomi mobile 및 huawei mobile)에서 다시 시작하지 않습니다.miui rome에서 백그라운드 서비스가 중지되었습니다.

어떻게 처리합니까? 매니페스트에

public class NotificationsService extends Service { 

@Override 
public void onCreate() { 
    ApplicationLoader.postInitApplication(); 
} 

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

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

public void onDestroy() { 
    Intent intent = new Intent("example.app.start"); 
    sendBroadcast(intent); 
} 
} 

:

<receiver android:name=".AppStartReceiver" android:enabled="true"> 
     <intent-filter> 
      <action android:name="example.app.start" /> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
     </intent-filter> 
    </receiver> 
+0

당신이 방송 수신기 코드를 게시나요? – W4R10CK

+0

@ W4R10CK 아직 없기 때문에 stackoverflow 메시지 : 한 번만 90 분마다 게시 할 수 있습니다. :/ –

+0

@ W4R10CK http://stackoverflow.com/questions/41918691/sending-broadcast-to-restart-service-to-keep-alive-not-working-currectly –

답변

3

샤오 미 사용자는 응용 프로그램이 자동으로 시작 할 수 있도록하는 기능이라는 응용 프로그램 권한, (서비스)을 가지고 있기 때문에 그것은 샤오 미에없는 새로운 않습니다.

이 같은 이동하여 앱이 자동으로 시작 할 수 있습니다 :

Settings > permissions > Autostart

또는

onDestroy() 내부 같은 Service 대신 onStartCommand(Intent intent, int flags, int startId) 방법 내부 START_STICKY을 사용하여 다시 시작하려고하지 마십시오.

은 다시 당신이 시작하는 서비스를 방송하지 보내고, 사용 onDestroy 제대로 :

@Override 
public void onDestroy() { 
Intent intent = new Intent("example.app.start"); 
sendBroadcast(intent); 
super.onDestroy(); 
} 
+0

사실입니다. Xiaomi에서는 새로운 것이 아닙니다. Mi Settings없이 프로그래밍 방식으로 서비스를 유지할 수있는 방법이 있습니까? –

+0

OnDestroy로 START_STICKY를 테스트하고 있지만 작동하지 않으며 서비스가 중지되었습니다! –

+0

아니요 MIUI의 메모리 용어로 사용자가 선택한 앱을 자동 시작하고'onDestroy' 내부에서'onStartCommand' 내부에서 'START_STICKY'를 사용하지 마십시오 – W4R10CK