Android miui rom上的后台服务已停止

Android miui rom上的后台服务已停止,android,android-service,Android,Android Service,我正在开发一个后台服务,在OnDestroy方法中,我调用了一个意图来再次启动我的服务。我不会再从小米手机和华为手机的miui开始 我该怎么处理 public class NotificationsService extends Service { @Override public void onCreate() { ApplicationLoader.postInitApplication(); } @Override public int onStartCommand(Inten

我正在开发一个后台服务,在OnDestroy方法中,我调用了一个意图来再次启动我的服务。我不会再从小米手机和华为手机的miui开始

我该怎么处理

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>

这对小米来说并不新鲜,因为小米有一个叫做apppermission的功能,用户必须允许app自动启动服务

按此操作并允许您的应用程序自动启动:

设置>权限>自动启动

或者

不要尝试在onDestroy中重新启动相同的服务,而是在onStartCommandIntent intent、int标志、int startId方法中使用START\u STICKY

同样,如果您发送的广播未启动服务,请正确使用onDestroy:

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

这是真的。这对小米来说并不新鲜。但是有没有办法在没有Mi设置的情况下以编程方式保持服务的活动状态?我正在用OnDestroy测试START\u STICKY,但没有工作,我的服务已经停止!不,这是MIUI中的一个记忆术语,用户必须自动启动所选应用程序,并且不要在onDestroy use inside中使用START\u STICKYonStartCommand@AliKouroshfar您正在发送广播,但未启动服务。这是真的。我正在发送广播。但是我有一个接收我的广播并启动我的服务的接收器。你发布广播接收器代码了吗?@W4R10CK还没有,因为stackoverflow说:你只能每90分钟发布一次/@W4R10CK@AliKouroshfar请看一看,这是不同供应商定制ROM中非常常见的问题,正如您所提到的。并且解决方案已经可用@Akki已建议。