开发者

how to get the result from a sub activity

开发者 https://www.devze.com 2023-01-10 04:48 出处:网络
When user presses a button from a webview, I open a scrollview act开发者_运维问答ivity with some buttons and edittext fields.

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

精彩评论

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

关注公众号