【发布时间】:2018-03-12 08:10:26
【问题描述】:
我在onStartCommand的服务中添加了以下代码-
Notification notification = new NotificationCompat.Builder(AbcService.this)
.setContentTitle("xyz")
.setTicker("xyz")
.setContentText("xyz")
.setSmallIcon(R.drawable.mevo_chat_mevopic)
.setOngoing(true).build();
startForeground(AppConstants.ABC,
notification);
和stopForeground(true); 在服务的onDestroy() 内。我希望服务即使在应用程序被销毁时也能运行,因为它是前台服务,但我看到有时它会运行,有时它会停止。我没有任何其他应用程序打开并且我的设备没有内存问题。我的前台服务被停止的可能原因是什么?我该如何解决这个问题?
【问题讨论】:
标签: android service foreground-service