我很新的到Android编程..我有这个问题..我想传递一个值,但结果是空..我不知道为什么会这样..谁能帮助我?提前致谢。我的代码是这样的..Android传递值为什么为null?
Manager.java
String prize="5";
Intent i = new Intent(Manager.this, Shop.class);
i.putExtra("Key", prize);
startActivity(i);
Shop.java
Intent myIntent = getIntent();
String receive = myIntent.getStringExtra("Key");
if (getIntent().getExtras() != null)
{
TextView tv = (TextView)findViewById(R.id.textView2);
tv.setText(receive);
}
else
{
TextView tv = (TextView)findViewById(R.id.textView2);
tv.setText("value is null"); //this is always the result
//why is it null??
}
第一次使用这个和检查数据是否来不来。 Toast.makeText(Shop.this,“”+ receive,Toast.LENGTH_LONG).show(); – TheLittleNaruto
@Kumar我试图Toast.makeText ......但价值仍是空 – user2599219
嘿请举杯它只是这一行 字符串低于收到= myIntent.getStringExtra(“重点”); 如果条件没有在里面。 – TheLittleNaruto