Android服务 - 在关闭任务后重新启动

时间:2016-07-24 17:42:58

标签: android firebase android-service

我希望在销毁活动后重新启动服务。

在服务中是对firebase-db的数据库引用。此服务的目的是在添加子项时向用户显示通知。

My Manifest.xml如下所示:

<application>
[...]
<service
    android:name=".FirebaseComponent.FirebaseDatabasePushService"
    android:process=":PushService"
    android:enabled="true"
    android:exported="false" />
</application>

我尝试使用public void onTaskRemoved(Intent rootIntent)并在startService(intent)中使用,但这也没有用。

我的onStartCommand(Intent intent, int flags, int startId)返回START_STICKY。

如何在用户杀死服务后重启服务?

1 个答案:

答案 0 :(得分:1)

据我所知,目前无法重启服务。我记得几个月前我有这个问题,唯一的解决办法是

  1. 完全停止服务 和
  2. 运行postDelayed,然后在5秒后重新启动它。
  3. 希望这有帮助!

相关问题