【发布时间】:2023-04-05 16:51:01
【问题描述】:
我在 android 中的推送通知有问题。
这是吗,我有一个有 2 个活动的应用程序,第一个是菜单,另一个我显示地图。
在应用程序中使用通知推送来更改地图。现在,当地图的活动在屏幕上可见并按下手机中的主页按钮时,这相信是在后台。
现在应用收到通知,打开通知并加载菜单 ok,更新地图数据并显示地图的活动,但返回菜单并按返回按钮退出应用并关闭活动,但出现在后台的地图的另一个活动。这不关闭。我能做什么???
请帮帮我!!!
收到通知时的消息代码是这样的:
@Override
protected void onMessage(Context context, Intent intent){
// Notificacion recibida: informamos al usuario
String message = "Notificación Recibida";
//"Id: " + intent.getExtras().getString("id") + " Status: " + intent.getExtras().getString("status");
//Se crea un nuevo manejador de notificaciones
NotificationManager manejadorNotificaciones = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//Se construye una notificacion basica
NotificationCompat.Builder notificacionPersonalizacion = new NotificationCompat.Builder(this).
setSmallIcon(drawable.ic_launcher).setContentTitle("Aviso SAT").setContentText(message);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Intent intentoMapaPush = new Intent(this, MenuPrincipal.class);
intentoMapaPush.putExtra("Push", "push");
PendingIntent contIntent = PendingIntent.getActivity(this, 0, intentoMapaPush, 0);
notificacionPersonalizacion.setContentIntent(contIntent);
notificacionPersonalizacion.setSound(alarmSound);
notificacionPersonalizacion.setAutoCancel(true);
Notification notificacion = notificacionPersonalizacion.build();
notificacion.flags= Notification.FLAG_AUTO_CANCEL;
manejadorNotificaciones.notify(NOTIF_ALERTA_ID, notificacion);
}
【问题讨论】:
-
向我们展示您的通知代码
标签: android android-activity push-notification broadcastreceiver