Java Android用户点击我的通知并返回到我的应用程序
我正在使用Java Android用户点击我的通知并返回到我的应用程序,java,android,android-intent,android-service,android-notifications,Java,Android,Android Intent,Android Service,Android Notifications,我正在使用startForefround()方法显示后台服务的通知 if (notif == null) { // Create the pending intent Intent intentForeground = new Intent(this, BackgroundLocationService.class) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY
startForefround()
方法显示后台服务的通知
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);
它正确地向用户显示通知,当我滑下通知栏时,我希望用户点击通知并返回到我的应用程序。我怎样才能做到这一点?使用这个
Notification notification = new Notification(R.drawable.logo2, "app is running on the background!", System.currentTimeMillis());
notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
notification.setLatestEventInfo(this, "title", "message!", contentIntent);
this.startForeground(1023, notification);
用这个
Notification notification = new Notification(R.drawable.logo2, "app is running on the background!", System.currentTimeMillis());
notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
notification.setLatestEventInfo(this, "title", "message!", contentIntent);
this.startForeground(1023, notification);
啊,我错过了主要的活动。课堂部分。谢谢啊,我错过了主要的活动。课堂部分。谢谢