【发布时间】:2017-01-29 06:11:14
【问题描述】:
我正在开发一个后台服务,并且在 OnDestroy 方法中,我调用了一个意图来重新启动我的服务。 miui rom(小米手机和华为手机)我没有重新开始。
我该如何处理?
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>
【问题讨论】:
-
你发布广播接收器代码了吗?
-
@W4R10CK 还没有,因为 stackoverflow 说:您每 90 分钟只能发布一次。 ://
-
@AliKouroshfar 请看看这个stackoverflow.com/a/56335831/5685911
-
正如您所提到的,这是在不同供应商的定制 ROM 中非常常见的问题。并且解决方案已经可用@Akki 建议了。