Android Activity跳转的小结
2010-10-19 20:15:08 来源:WEB开发网text = getIntent().getStringExtra("request_text_for_main");
request_text.setText(text);
}
btn = (Button)this.findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(SecondActivity.this,ThirdActivity.class);
i.putExtra("request_text_for_second", text+" "+"从SecondActivity传递到ThirdActivity");
startActivityForResult(i, SECOND_REQUEST_CODE);
}
});
finalBtn = (Button)this.findViewById(R.id.finalBtn);
finalBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent();
i.putExtra("final_request", text+" "+"从SecondActivity最后传递到Main");
setResult(Activity.RESULT_FIRST_USER,i);
finish();
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==SECOND_REQUEST_CODE && resultCode==Activity.RESULT_OK){
if(data != null) {
text = data.getStringExtra("request_text_for_third");
request_text.setText(text);
}
}
}
}
public class SecondActivity extends Activity{
private TextView request_text;
private Button btn,finalBtn;
private final int SECOND_REQUEST_CODE = 2;
private String text;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
request_text = (TextView)this.findViewById(R.id.request_text);
if (getIntent().getStringExtra("request_text_for_main") != null) {
text = getIntent().getStringExtra("request_text_for_main");
更多精彩
赞助商链接