谢谢!我有两个.java类作为trial.java和CommonActivity.java:
public void onClick(View v)
{
switch (v.getId())
{
case R.id.btnSequence:
Intent intent1 = new Intent();
intent1.setClass(this,CommonActivity.class);
Bundle bun1 = new Bundle();
bun1.putString("String_key", "value1");
intent1.putExtras(bun1 );
startActivity(intent1);
break;
case R.id.btnVideo:
Intent intent2 = new Intent();
intent2.setClass(this,CommonActivity.class);
Bundle bun2 = new Bundle();
bun2.putString("String_key", "value2");
intent2.putExtras(bun2);
startActivity(intent2);
break;
case R.id.btnInfo:
Intent intent3 = new Intent();
intent3.setClass(this,CommonActivity.class);
Bundle bun3 = new Bundle();
bun3.putString("String_key", "value3");
intent3.putExtras(bun3);
startActivity(intent3);
break;
}
}
在CommonActivity.java中我想做这样的事情:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Bundle bun = new Bundle();//am i doing wrong here, where are bun1,bun2 and bun3 of my trialactivty.java
Intent getIntent = new Intent();
bun = getIntent.getExtras();
String param = bun.getString("String_key");
if(param.equals("value1"))
{
setContentView(R.layout.main1);
}
if (param.equals("value2"))
{
setContentView(R.layout.main2);
}
if (param.equals("value3"))
{
setContentView(R.layout.main3);
}
}
同时在网上搜索我与 getExtras 和getextra.can混淆任何人请举例说明使用getExtra vs getExtras的场景以便我可以决定使用更好我的申请中的一个
答案 0 :(得分:0)
以下是从新活动中的意图中检索数据的方法......
Bundle callerBundle = getIntent()。getExtras(); Object obj = callerBundle.getString(“id”);
如果你做了类似的事情,这将有用。
myIntent.putExtra(“id”,(Object)obj);
在您之前的活动中