我想创建Service using bindService 方法.但是,当我关闭一个Activity时,我的服务被销毁了,我不希望这样.
我尝试使用startForeground(NOTIFICATION_ID, notification);服务onCreate 将服务放在前台 ,但服务仍然会破坏.
现在我尝试使用call两个方法同时启动Service:
Intent bindIntent= new Intent(this, ServiceC.class);
startService(bindIntent);
bindService(bindIntent, onService, BIND_AUTO_CREATE);
Run Code Online (Sandbox Code Playgroud)
通过调用这两个方法Service不会被破坏.我的应用程序正常使用此方法.
有人可以向我解释这是否是一个好方法,或者如果不是,请你能否解释为什么startForeground(NOTIFICATION_ID, notification);不起作用?
使用bindService的最佳方法是什么,但同时我不希望服务自行销毁.
| 归档时间: |
|
| 查看次数: |
6212 次 |
| 最近记录: |