I need to transfer additional data from an Intent to the calling activity. The base activity does "startActivityForResult()".
The nested activity sets the result and puts additional data in a click-listener:
public void onClick(View v) {
setResult(LOGIN_RESULT_IN);
LoginActivity.this.getIntent().putExtra("username", userStr);
LoginActivity.this.getIntent().putExtra("password", passStr);
LoginActivity.this.finish();
}
The calling activity checks the data with:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
preferences.username = data.getStringExtra("username");
preferences.password开发者_运维知识库 = data.getStringExtra("password");
}
however this return always null. Why doesn't it work?
try this code
public void onClick(View v) {
Intent intent=new Intent();
intent.putExtra("username", userStr);
intent.putExtra("password", passStr);
setResult(LOGIN_RESULT_IN,intent);
LoginActivity.this.finish();
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
preferences.username = data.getStringExtra("username");
preferences.password = data.getStringExtra("password");
}
精彩评论