user3737118
user3737118

Reputation: 35

Pass data from one activity to another with notification manager

I need to spend a given activity to another using the notification manager. This is the code of the notification.

private void notificacion(){
    // Preparamos el intent que será lanzado si la notificación es seleccionada
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    Intent intento = new Intent(PrincipalActivity.this, ActualizarVersion.class);
    intento.putExtra("versionnueva",VersionNueva);
    intento.putExtra("versionactual",VersionActual);

    intento.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent pIntent = PendingIntent.getActivity(PrincipalActivity.this, 0, intento, 0);

    // Creamos la notificación.
    CharSequence ticker = "Aviso de actualización";
    CharSequence contentTitle = "Calendario Verallia Sevilla";
    CharSequence contentText = "Hay disponible una nueva actualización";
    Notification noti = new NotificationCompat.Builder(PrincipalActivity.this)
            .setContentIntent(pIntent)
            .setTicker(ticker)
            .setContentTitle(contentTitle)
            .setContentText(contentText)
            .setSmallIcon(R.drawable.icono_aplicacion_pequeno)
            .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000})
            .setSound(soundUri)
            .build();
    NotificationManager notificationManager =
            (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    // Ocultamos la notificación si ha sido ya seleccionada
    noti.flags |= Notification.FLAG_AUTO_CANCEL;


    notificationManager.notify(0, noti);
    //Log.i(TAG, "Servicio running");
}

and this is where I collect data on activity ActualizarVersion

public void RecibirDatos(){
    Bundle extras = getIntent().getExtras();
    String versionnueva = extras.getString("versionnueva");
    String versionactual = extras.getString("versionactual");

    VersionActual=versionactual;
    VersionNueva=versionnueva;
}

When receiving the data, the intent is null and collects the data. How can I do this?

Upvotes: 3

Views: 1763

Answers (1)

starkshang
starkshang

Reputation: 8538

Replace

PendingIntent pIntent = PendingIntent.getActivity(PrincipalActivity.this, 0, intento, 0);

with

PendingIntent pIntent = PendingIntent.getActivity(PrincipalActivity.this, 0, intento, PendingIntent.FLAG_UPDATE_CURRENT);

Because the last parameter is flag to indicate how to control which unspecified parts of the intent that can be supplied when the actual send happens. So you can't set its value to 0.

Please take a look at PendingIntent api docs.

Upvotes: 3

Related Questions