1.在另一个活动中成功收到Msg字符串值 2.在另一项活动中未成功收到d和Time int值
EditText Msgbody=(EditText)findViewById(R.id.messageText);
Msg=Msgbody.getText().toString();
EditText Datebody = (EditText)findViewById(R.id.dateText);
d=Integer.parseInt(Datebody.getText().toString());
EditText Timebody=(EditText)findViewById(R.id.timeText);
Time=Integer.parseInt(Timebody.getText().toString());
Intent m=new Intent(this,Listview.class);
Bundle extra=new Bundle();
extra.putString("Message",Msg);
extra.putInt("Date",d);
extra.putInt("Time",Time);
m.putExtras(extra);
startActivity(m);
3.intent recieving code
Bundle extra=getIntent().getExtras();
String message1=extra.getString("Message");
TextView msg=(TextView)findViewById(R.id.msgtext);
msg.setText(message1);
int D=-1;
D=extra.getInt("Date",0);
if(D>0){
TextView dt=(TextView)findViewById(R.id.dateText);
if(dt!=null)
dt.setText(valueOf(D));}
int time1=extra.getInt("Time",0);
TextView ti=(TextView)findViewById(R.id.timeText);
if(ti!=null)
ti.setText(valueOf(time1));
答案 0 :(得分:0)
在接收意图中,您应该获取以下值:
if(extra.getExtras() != null)
date = extra.getExtras().getInt("date");
另外,请在传递之前检查您的变量是否为空