からいくつかの値を取得し、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
ようなデータを取得する 2 番目です。
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();
}
});
}}
このバグを解決する方法、ありがとう