我沒有看到startActivity()
任何地方......所以我把你的代碼應該如何和你實現它。
name=(EditText)findViewById(R.id.editText);
String str = name.getText().toString();
Intent intent = new Intent(WelcomeActivity.this, ResultActivity.class);
intent.putExtra("str", str);
startActivity(intent);
然後在你的ResultActivity
你這樣做:
TextView t = (TextView) findViewById(R.id.textResult);
Intent intent = getIntent();
Bundle b = intent.getExtras();
if(b!=null){
String name =(String) b.get("str");
t.setText(name);
}
好了,你可以使用SharedPreferences做到這一點:
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("NamePlayer", name); //Here you save the text of your edittext
editor.commit();
然後在你的結果的活動做到這一點:
SharedPreferencessharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext));
String name =sharedPreferences.getString("NamePlayer", "NoName"));
你是否開始與該意圖或與其他? –
@Victoria你確定R.id.textResult是正確的ID嗎? – IgorB