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