Context.startService安卓:启动服务与Context.startService VS PendingIntent.getService
Intent intent = new Intent(context, MyService.class);
context.startService(intent);
PendingIntent.getService
Intent intent = new Intent(context, MyService.class);
PendingIntent pi = PendingIntent.getService(context, 0, intent, 0);
pi.send();
问题
- 什么时候可以使用Context.startService和PendingIntent启动服务?
- 为什么你会用另一个呢?
那么,你有没有想过用PendingIntent启动服务? – 2012-02-07 23:19:18
如果您想在不久的将来启动服务,这将是理想的情况。假设我有一个通知,显示用户帐户可用的新更新。理想情况下,会有一个挂起的意图,建立连接到服务器并下载此信息。我希望在用户点击通知后立即完成,这样我就等待用户的方便,或者如果用户不关心他们可以取消通知,并且下一个新更新将以同样的方式作出反应。 – JoxTraex 2012-02-08 00:01:10
很好的解释,谢谢! – damluar 2014-06-02 11:22:11