我正在使用安卓清单中的以下代码在我的应用程序中运行服务:<service android:name="com.sam.cam.CallDetectService" />
问题是,当应用程序从taskmanager手动关闭时,服务被关闭,即使应用程序关闭,我如何继续运行服务。
我看到watsapp、gmail等应用程序在使用taskmanager关闭时仍然在后台运行。这是如何做到的?
发布于 2014-03-18 17:10:44
您必须在服务类中使用“startForeground()”,
例如,
// on oncreate() of service class
Notification notification = new Notification.Builder(this)
.setContentTitle("TOPAZ-PACS")
.setContentText("")
.setSmallIcon(com.emdsys.android.pacs.R.drawable.ic_launcher)
.build();
notification.flags = Notification.FLAG_ONGOING_EVENT;
startForeground(1234, notification);https://stackoverflow.com/questions/22474353
复制相似问题