Sending data from one activity to another startactivityforresult

android

Solution

don't need start activity in second class:

you need change your code with:

Intent i = new Intent();  // or // Intent i = getIntent()
i.putExtra("TAG",input);
setResult(RESULT_OK , i);         
finish();

and for cancel that,

setResult(RESULT_CANCELED, i);        
finish();

Problem

I searched on the forums but couldn't find the right answer for me. I've included the relevant parts below ACTIVITY ONE ``` implicitActivationButton.setOnClickListener(new OnClickListener() { // Call startImplicitActivation() when pressed @Override public void onClick(View v) { Intent myIntent = new Intent(ActivityLoaderActivity.this, ExplicitlyLoadedActivity.class); startActivityForResult(myIntent, GET_TEXT_REQUEST_CODE); } }); ``` and a little lower ``` protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.i(TAG, "Entered onActivityResult()"); String input=data.getStringExtra(TAG); mUserTextView.setText(input); } ``` This is activity 2 after user enters some data ``` String input=mEditText.getText().toString(); Intent i = new Intent(ExplicitlyLoadedActivity.this, ActivityLoaderActivity.class); i.putExtra("TAG",input); startActivity(i); this.setResult(RESULT_OK); finish(); ``` No error messages at all but the text on screen doesnt update. it is supposed to

Original source