Met*_*urf 15 android android-intent android-context android-pendingintent
Context.startService
Intent intent = new Intent(context, MyService.class);
context.startService(intent);
Run Code Online (Sandbox Code Playgroud)
PendingIntent.getService
Intent intent = new Intent(context, MyService.class);
PendingIntent pi = PendingIntent.getService(context, 0, intent, 0);
pi.send();
Run Code Online (Sandbox Code Playgroud)
问题
Jox*_*aex 19
确实没有区别.
具体来说,Context方法用于直接启动它,因为PendingIntent通常与一个通知一起使用,以便在点击它时触发此意图,该意图被延迟直到用户点击它(通常).然而; 你通常不会直接发送PendingIntent,因为那不是它的用途.
PendingIntent是一个待处理的待处理意图,意味着它现在不应该发生,但在不久的将来.而对于Intent,它会在此刻发送.
如果PendingIntent在使用时没有挂起,那么它不再是PendingIntent,它实际上是一个Intent.彻底击败目的.
| 归档时间: |
|
| 查看次数: |
11924 次 |
| 最近记录: |