onActivityResult method not being called Android

Posted by Chintan on Stack Overflow See other posts from Stack Overflow or by Chintan
Published on 2013-03-28T18:22:42Z Indexed on 2013/10/23 15:54 UTC
Read the original article Hit count: 185

Filed under:
|

I am trying to send data from child activity to parent. But somehow, onActivityResult(..) is not getting called. here is code

Parent activity

selectedText.setOnTouchListener(new OnTouchListener() {



    public boolean onTouch(View v, MotionEvent event) {
                    if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                        Intent intent = new Intent(Parents.this,Child.class);
                        startActivityForResult(intent, 1);
                    }
                    return true;
                }
            });


        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            switch (requestCode) {
            case 1:
                if (resultCode == RESULT_OK) {
                    if (data.hasExtra("selText")) {
                        selectedText.setText(data.getExtras().getString(
                                "selText"));

                    }
                    break;
                }
            }

Child Activity: I can see selected value set in the setResult(). But after finish of child activity, it's not going back to parent activity.

textListView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int myItemInt,
                    long arg3) {
                selectedFromList =(String) (textListView.getItemAtPosition(myItemInt));
                Intent data = new Intent();
                data.putExtra("selText", selectedFromList);
                setResult(RESULT_OK,data);
                finish();
            }
        });

© Stack Overflow or respective owner

Related posts about android

Related posts about activity