【问题标题】:activity remains open and doubles when receive notification push活动保持打开状态并在收到通知推送时翻倍
【发布时间】: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


【解决方案1】:

您正在点击通知时启动新活动。您必须从通知中撤消旧的暂停活动,您的问题就会解决。 Use android:launchMode="singleInstance" 在清单文件的活动声明中。

一旦这样做,让我知道。

【讨论】:

  • 嗨,使用 launchmode="singleInstance" 撤销旧的暂停活动?
  • 如果您选择 singleInstance 那么您将无法在活动堆栈developer.android.com/intl/es/guide/topics/manifest/… 上推送新活动。所以每次你想从 singleInstance Activity 开始新的活动时,它都会被关闭。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多