我们正在开发一个在前台服务中运行MQTT的应用程序。问题出在小米Redmi Note 7上,该服务在我们终止该应用程序后被终止,但在其他品牌上运行正常。我没有在Oppo和Vivo上测试该应用程序,但是当我搜索它们时也遇到了问题。在服务的onCreate
方法中,我调用了startForeground(NOTIFICATION_ID, notification)
,清单中的服务声明如下:
<service android:name=".service.mqtt.MqttService" android:enabled="true" android:exported="false" android:foregroundServiceType="location" />
我也将
foregroundServiceType
更改为connectedDevice|dataSync|mediaPlayback
并添加了android:stopWithTask="false"
并以START_STICKY
的服务方法返回了onStartCommand
,但仍无法正常工作。
我们正在开发一个在前台服务中运行MQTT的应用程序。问题出在小米Redmi Note 7上,该服务在我们终止该应用程序后被终止,但在其他品牌上运行正常。我没有...
最后我找到了答案here