我从 an 中获取一些值,Activity
并在onActivityResult()
,onActivityResult()
中获取这些值,但收到的数据null
CODE
是MainActivity
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
// TODO Auto-generated method stub
if(item.getItemId() == R.id.action_settings){
Intent intent = new Intent(MainActivity.this, AddDetailActivity.class);
startActivityForResult(intent, request_code);
}
return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == request_code){
if(resultCode == RESULT_OK){
String name = data.getExtras().getString(AddDetailActivity.NAME_KEY);
String address = data.getExtras().getString(AddDetailActivity.ADDRESS_KEY);
Toast.makeText(MainActivity.this, "Name is : " + name + " Address : " + address, Toast.LENGTH_LONG).show();
}
}
}
这是Activity
我第二次获得这样的数据:
public class AddDetailActivity extends Activity {
public static final String NAME_KEY = "U-name";
public static final String ADDRESS_KEY = "add";
protected EditText name_et, address_et;
protected String put_name, put_address;
protected Button button = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_detail);
name_et = (EditText) this.findViewById(R.id.name_editText);
address_et = (EditText) this.findViewById(R.id.address_editText);
put_name = name_et.getText().toString();
put_address = address_et.getText().toString();
//put_type = null;
button = (Button) findViewById(R.id.add_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.putExtra(NAME_KEY, put_name);
intent.putExtra(ADDRESS_KEY, put_address);
setResult(RESULT_OK, intent);
finish();
}
});
}}
这个bug怎么解决,谢谢