MainActivityアンドロイドintent.getStringExtra()の戻りヌル
public class MainActivity extends AppCompatActivity {
private static final int REQ_CODE_TO_ADD = 123;
final ArrayList<Contact> allContact = new ArrayList();
ArrayList<String> name = new ArrayList();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Intent intent = new Intent(this,DetailActivity.class);
Button addbt = (Button)findViewById(R.id.addbt);
public void onClickAdd(View v){
Intent intent = new Intent(this,AddContactActivity.class);
startActivityForResult(intent,REQ_CODE_TO_ADD);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == REQ_CODE_TO_ADD){
if(resultCode == 0){
Intent intent = getIntent();
String name2 = intent.getStringExtra("namev");
String email2 = intent.getStringExtra("emailv");
String birthday2 = intent.getStringExtra("birthdayv");
Log.d("AAA",">>>:"+name2);
Contact person = new Contact(name2,email2,birthday2);
allContact.add(person);
}}
}
}
AddContactActivity
public class AddContactActivity extends AppCompatActivity {
private static final int REQ_CODE_TO_MAIN = 321;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_contact);
}
public void onClickOk(View v){
EditText name = (EditText)findViewById(R.id.nameet);
EditText email = (EditText)findViewById(R.id.email);
EditText birthdate = (EditText)findViewById(R.id.birthdate);
Intent intent = new Intent();
intent.putExtra("namev",name.getText().toString());
intent.putExtra("emailv",email.getText().toString());
intent.putExtra("birthdayv",birthdate.getText().toString());
setResult(0,intent);
finish();
}
}
AddContactActivity Iすでにintent.putExtra name.getText()。toString()を使用し、MainActivity
に意図を送りますなぜMainActivity Log.d出力のonActivityResult()がnullですか?
のようにコードを修正し、あなたが正しい意図を使用していることを確信していますか? 'getIntent();'?私はそれが 'データ'でなければならないと思う... – Opiatefuchs