【发布时间】:2013-10-15 14:38:18
【问题描述】:
我发现下面的代码是多余的。我在这里缺少一些基本的东西吗?有没有办法减少这里的重复代码。我可以使用 Intent 或 PendingIntent 对象吗,为什么同时使用?
Intent updateUI = new Intent(SENDTOBACKGROUND_SERVICE);
updateUI.putExtra("Signal", God.YELLOW);
sendBroadcast(updateUI);
Intent sendNotification = new Intent(DriverService.this, DriverHome.class);
sendNotification.putExtra("Signal", God.YELLOW);
PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), 0, sendNotification, PendingIntent.FLAG_UPDATE_CURRENT);
Notification n = new NotificationCompat.Builder(DriverService.this)
.setContentTitle("Attempting to update location")
.setContentText("Cab @(last) " + currentLocationInText)
.setSmallIcon(R.drawable.yellow).setContentIntent(pIntent).setAutoCancel(true)
.build();
((NotificationManager) DriverService.this.getSystemService(NOTIFICATION_SERVICE)).notify("Taxeeta", R.id.cabLocation, n);
【问题讨论】:
-
PendingIntent 使您能够使用您的权限在另一个可能缺少此类权限的应用程序中运行您的代码。
标签: android android-intent android-pendingintent