1, un premier, un transfert simple.
Envoyer:
commutateur (v.getId ()) {
cas R.id.btn1:
EditText editText = findViewById (R.id.editText);
intention Intent = new intention (ce, my1Activity.class);
intent.putExtra ( "données", editText.getText () toString ().);
startActivity (intention);
Pause;
recevoir:
intention Intention = getIntent ();
Chaîne str1 = intent.getStringExtra ( "data");
TextView textView = findViewById (R.id.textView3);
textView.setText (ch1);
2, deuxième: bundle d'utilisation. Forex MT4 Tutoriel
Envoyer:
Bundle = nouveau paquet ();
bundle.putString (. "Data1", editText.getText () toString () + editText.getText () toString ().);
intent.putExtras (bundle);
startActivity (intention);
recevoir:
Bundle = getIntent () getExtras ();.
textView1.setText (bundle.getString ( "Data1") toString ().);
3, relativement complexe:
L'expéditeur:
cas R.id.btn1:
EditText editText = findViewById (R.id.editText);
intention Intent = new intention (ce, my1Activity.class);
// définition.
CarteCarte = new HashMap <> ();
map.put ( "key1", "valeur1");
map.put ( "key2", "valeur1");
Liste> Liste = new ArrayList <> ();
list.add (carte);
// doit être défini pour transmettre une liste des budnle de transfert requise
ArrayList <Object>,这个是必须要的!
Bundle = new Bundle ();
ArrayList bundlelist = new ArrayList ();
bundlelist.add (liste);
bundle.putParcelableArrayList ( "liste", bundlelist);
intent.putExtras (bundle);
startActivity (intention);
Pause;
recevoir:
// paramètres de réception
du Bundle le faisceau de ses getExtras getIntent = () () ;.
La liste ArrayList = bundle.getIntegerArrayList ( "liste");
// dans la liste des paramètres, la conversion
Liste <Carte <String, Object >> listes = (Liste <Carte <String, Object >>) list.get (0);
Chaîne sResult = "";
pour (Carte <String, Object> m: listes) {
pour (String k: m.keySet ()) {
sResult + = "\ r \ n" + k + ":" + m.get (k);
}
}
TextView textView = findViewById (R.id.textView3);
TextView textView1 = findViewById (R.id.textView4);
textView1.setText (sResult);
4, définir des variables globales:
Définition:
public class my_data {
public static chaîne m1;
static Integer d1;
}
使用:
textView.setText (my_data.m1);