我有一个场景,通过登录页面登录后,我尝试使用此解决方案将会话名称传递给homeactivity类。
在MainActivity类中:
progress = ProgressDialog.show(MainActivity.this,
"start...", "welcome "
+ rt2.getText().toString(), false,
false);
int secondsDelayed = 1;
new Handler().postDelayed(new Runnable() {
public void run() {
startActivity(new Intent(MainActivity.this,
HomeActivity.class));
Intent intent = new Intent(
getApplicationContext(),
HomeActivity.class);
intent.putExtra("name", rt2.getText()
.toString());
Log.d("MainActivity.class", rt2.getText()
.toString());
finish();
}
}, secondsDelayed * 1000);
在家庭活动课程中:
String name;
name = getIntent().getExtras().getString("name");
Log.d("HomeActivity.class", name.toString());
我有Android应用程序的崩溃,为什么?
提前谢谢。
答案 0 :(得分:0)
使用intent
Intent以下列HomeActivity
活动开始:
Intent intent = new Intent(getApplicationContext(),HomeActivity.class);
intent.putExtra("name", rt2.getText().toString());
startActivity(intent);
目前,您没有将intent
name
密钥传递给startActivity
答案 1 :(得分:0)
请这样: -
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent = new Intent(
getApplicationContext(),
HomeActivity.class);
intent.putExtra("name", rt2.getText()
.toString());
startActivity(intent);
Log.d("MainActivity.class", rt2.getText()
.toString());
finish();
}
}, secondsDelayed * 1000);