Problème avec données récupérées dans getIntent()
Bonsoir,
j'ai un petit souci dans mon appli...
Je crée des notifications avec pour Intent le lancement d'une activity FinTelechargement avec un ID... Or lorsque j'ai plusieurs notification, dans mon activity FinTelechargement je me retrouve toujours avec le même ID dans le getExtra (et pourtant je vérifie bien que je crée mes Intent avec la bonne valeur).
Donc je commence à me dire qu'il y a quelque chose que je n'avais pas compris au sujet des Intent et getIntent() et qu'une fois un Intent créé sur une class les autres n'étaient pas créés ?
Voici mon code :
La création de la notification :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| //Méthode qui créer la notification
private void createNotify(int FileLenght, int idTelec){
//ID unique
System.out.println("createNotify identifiant : "+idTelec);
//On créer un "gestionnaire de notification"
notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notification = new Notification(R.drawable.telecharger, "Téléchargement en cours", System.currentTimeMillis());
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notif);
contentView.setImageViewResource(R.id.image, R.drawable.telecharger);
contentView.setTextViewText(R.id.nomFig,figure.getText());
contentView.setProgressBar(R.id.status, FileLenght, 0, false);
contentView.setTextViewText(R.id.size, "0/"+FileLenght+"kB");
contentView.setTextViewText(R.id.pourcent, "0%");
notification.contentView = contentView;
//On créé l'Intent qui va nous permettre d'afficher l'autre Activity
Intent notificationIntent = new Intent(this, FinTelechargement.class);
notificationIntent.putExtra("id",idTelec);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
System.out.println("ID intent : "+notificationIntent.getIntExtra("id", 0));
//Enfin on ajoute notre notification et son ID à notre gestionnaire de notification
notificationManager.notify(idTelec, notification);
} |
L'activity finTelechargement :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| public class FinTelechargement extends Activity {
private kompakomboT telec;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(this.getClass().getName(), "onCreate");
//on lui associe le layout affichagelistevideomain.xml
setContentView(R.layout.fintelechargement);
//si le fichier existe déjà on demande à l'utilisateur s'il veut le télécharger à nouveau
System.out.println("Click sur annulation");
AlertDialog.Builder annuler = new AlertDialog.Builder(FinTelechargement.this);
telec = ((kompakomboT)getApplicationContext());
final int idTelec=this.getIntent().getIntExtra("id", 0);
annuler.setMessage("Voulez-vous annuler ce téléchargement")
.setCancelable(true)
.setPositiveButton("Oui", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
telec.supprTelech(String.valueOf(FinTelechargement.this.getIntent().getIntExtra("id", 0)));
System.out.println("Suppression ID : "+FinTelechargement.this.getIntent().getIntExtra("id", 0));
finish();
}
})
.setNegativeButton("Non", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
annuler.setOnCancelListener(new DialogInterface.OnCancelListener ()
{
@Override
public void onCancel(DialogInterface dialog)
{
finish();
}
});
AlertDialog alertDL = annuler.create();
alertDL.show();
}
} |
je me doute que c'est lié à ce que je peux lire là:
Citation:
Your Intent is the same on all non-extra parameters (e.g., action). Hence, you get the same PendingIntent back from your getActivity() call, as there is only one PendingIntent per distinct Intent. You need to change something -- beyond extras -- in your second Intent, such as a different action string.
Mais je ne vois pas comment contourner mon problème...
Merci beaucoup pour votre aide.