2010-11-06 2 views

Répondre

11

Utilisation Intent.putExtra(..):

intent.putExtra("keyName", "somevalue"); 

Cette méthode est surchargée et prend différents types comme second argument: int, byte, cordes, divers tableaux ..

Pour obtenir les données sur l'utilisation appropriée getXYZExtra() . Pour ce chaîne est:

getStringExtra(String keyName) 
+0

mais comment puis-je obtenir les données de mon activité? Quel est l'événement qui est appelé quand et l'activité obtient une intention? – Mars

+1

'activity.getIntent()' ou 'this.getIntent()' –

+0

puis-je le mettre dans OnCreate()? – Mars

26

MainActivity

Intent intent = new Intent(MainActivity.this,SecondActivity.class); 
intent.putExtra("extra_text", string); 
startActivity(intent); 

SecondActivity

String text = getIntent().getStringExtra("extra_text"); 
+2

Réponse parfaite. Court et avec le nécessaire. – Shudy

Questions connexes