我發現下面的代碼是多餘的。我在這裏錯過了什麼基礎?有沒有辦法在這裏減少重複的代碼。我可以使用Intent或PendingIntent對象,爲什麼呢?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使您能夠在另一個可能缺少此類權限的應用中使用您的權限運行代碼。 – Kuffs