Carthage Posted May 29, 2011 Share Posted May 29, 2011 Bonjour à tous ! Voilà, je vous expose mon problème. J'aimerai transmettre des données entre Activity. Je m'explique, lors du passage à une autre Activity, j'aimerai que l'ancienne Activity transmette un paramètre à la nouvelle. Quelqu'un aurait-il une méthode pour cela ? Cordialement. Link to comment Share on other sites More sharing options...
Carthage Posted May 29, 2011 Author Share Posted May 29, 2011 Bon voilà, en fouillant un peu, j'ai réussi à trouver les fonctions nécessaires. Voici ce que celà donne : Intent myIntent = new Intent(this, SecondActivity.class); myIntent.putExtra("myInfo", map); Bundle bundy = this.getIntent().getExtras(); String myCoolInfo = bundy.getString("myInfo"); Mais maintenant, j'ai une erreur :s En effet, lorsque je passe en débogage et que je mets un point d'arrêt juste après la dernière fonction pour vérifier l'état des variables, voilà ce que j'ai : - pour la variable bundy : Bundle[{myInfo={img=2130837515, titre=Hello, description=250}}] - pour la variable myCoolInfo : NULL Mais comment puis-je faire pour récupérer directement le champ "titre" dans la variable myCoolInfo ? D'avance merci Link to comment Share on other sites More sharing options...
nahzhir Posted May 29, 2011 Share Posted May 29, 2011 Bonjour, En fait, "myInfo" est une map, donc tu ne pourras pas avoir la valeur des maps par bundy.getString("myInfo"); tu devrais faire : Map map = (Map) bundy.getObject("myInfo"); map.get("titre") De cette façon tu récuperes d'abord ton objet puis ensuite de l'exploite de la façon que tu veux. Link to comment Share on other sites More sharing options...
Carthage Posted May 30, 2011 Author Share Posted May 30, 2011 Bonjour, effectivement, comme ça, ça va mieux, merci :) En revanche, un autre problème intervient tout de suite. Voici mon code : Bundle bundy = this.getIntent().getExtras(); Map map = (Map) bundy.get("myInfo"); if (map.get("titre")=="Hello") { // Déclaration } Avec map ayant la valeur suivante : {img=2130837515, titre=Hello, description=250}, la fonction if est comme inexistante. En effet, il passe au travers du if est n'exécute donc pas le code se trouvant dans ce fameux if. Pour moi, tout à l'air correct et je ne vois pas comment je peut faire pour que ce code soit exécuter. Merci ! Link to comment Share on other sites More sharing options...
frozenscar Posted May 30, 2011 Share Posted May 30, 2011 Salut, pour les chaines de caracteres, utilise la methode .equal() ++ Link to comment Share on other sites More sharing options...
Honikou Posted May 30, 2011 Share Posted May 30, 2011 Tu peux aussi utiliser un singleton Link to comment Share on other sites More sharing options...
Mc Flurry Posted May 30, 2011 Share Posted May 30, 2011 Mais, tu n'utilise pas getObject ?! Link to comment Share on other sites More sharing options...
Carthage Posted May 30, 2011 Author Share Posted May 30, 2011 @Mc Flurry : Non je n'utilise pas getObject car je ne sais pas pourquoi, mais ça ne veut pas fonctionner chez moi :( Sinon avec : if (map.get("titre").equals("Hello")) { // Déclaration } ça fonctionne très bien. Un grand merci pour votre aide !! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.