1
我使用startForefround()
方法顯示背景爲Service
的Notification
。Android用戶點擊我的通知並返回到我的應用程序
if (notif == null) {
// Create the pending intent
Intent intentForeground = new Intent(this, BackgroundLocationService.class)
.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendIntent = PendingIntent.getActivity(getApplicationContext(), 0, intentForeground, 0);
notif = new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.ic_launcher)
.setDefaults(Notification.DEFAULT_ALL)
.setTicker(getText(R.string.location_service_starting))
.setOnlyAlertOnce(true)
.setOngoing(true)
.setContentIntent(pendIntent)
.build();
notif.flags |= Notification.FLAG_NO_CLEAR;
}
startForeground(notificationID, notif);
它正確地顯示通知用戶,當我滑下通知欄我想有用戶點擊此通知並返回到我的應用程序。我怎樣才能做到這一點?
啊,我是缺少MainActivity.class部分。謝謝! –