开发者

how to get the result from a sub activity

When user presses a button from a webview, I open a scrollview act开发者_运维问答ivity with some buttons and edittext fields.

Once the user enters the fields and presses the 'create' button, from scrollview activity, I want the results from the called activity to be accessible.

How can I do thi?


you call setResult on the activity

I've done something like this:

private void executeDone() {
    Intent resultIntent = new Intent();
    resultIntent.putExtra("value", TextEntryActivity.this.et.getText().toString());
    setResult(Activity.RESULT_OK, resultIntent);
    finish();
}

In the calling Activity:

public void launchPreferedNameEdit() {
    Intent foo = new Intent(this, TextEntryActivity.class);
    foo.putExtra("value", objItem.getPreferedNickname());
    this.startActivityForResult(foo, EDIT_PREFERED_NAME);
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
        case EDIT_PREFERED_NAME:
            try {
                String value = data.getStringExtra("value");
                if (value != null && value.length() > 0) {
                }
            } catch (Exception e) {
            }
            break;
        default:
            break;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜