2017-01-13 14 views
4

私のサービスでは、START_STICKYを返して、私がアプリを終了した後にもう一度Serviceを再起動させました。
どのように私はこのケースを扱うことができるサービスを終了した後にサービスが再開しない

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

(サービス再起動しない)私は、テストを持って、それは、デバイスSamsungで働く、SonyLGしかしXiaomiにそれは動作しません。どんな助けや提案もすばらしいでしょうか?小米科技およびin vivoのような

/** 
* Constant to return from {@link #onStartCommand}: if this service's 
* process is killed while it is started (after returning from 
* {@link #onStartCommand}), then leave it in the started state but 
* don't retain this delivered intent. Later the system will try to 
* re-create the service. Because it is in the started state, it will 
* guarantee to call {@link #onStartCommand} after creating the new 
* service instance; if there are not any pending start commands to be 
* delivered to the service, it will be called with a null intent 
* object, so you must take care to check for this. 
* 
* <p>This mode makes sense for things that will be explicitly started 
* and stopped to run for arbitrary periods of time, such as a service 
* performing background music playback. 
*/ 
public static final int START_STICKY = 1; 
+0

サービス中のOntaskRemovedをオーバーライドし、再びサービス –

+0

を開始します。残念ながら、ontaskRemovedも、ここで私の質問のようにデバイスxiaomiで呼び出されません。http://stackoverflow.com/questions/41629152/service-ontaskremoved-not-call-when-kill -app-in-some-device –

+0

もしそうなら、それは 'Xiaomi'ベンダー固有の問題だと思います。 – Onik

答えて

0

Androidのドキュメントからいくつかのデバイスは、アプリのサービスが殺された後、自動的に再起動することを可能にする「オートスタート」と呼ばれる余分な権限を持っています。あなたはXiaomiの追加のアクセス許可で見つけることができます。