Reputation: 225
I am calling the intent from FirstActivity to SecondActivity.I called the startActivityForResult with the requestCode and Intent but in the SecondActivity setResult is calling the SecondActivity instead of calling the FistActivity . This is my code
FirstActivity
Intent i = new Intent(getApplicationContext(), SecondActivity.class);
startActivityForResult(i,1);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Toast.makeText(getApplicationContext(),"result"+data.getStringExtra("data"),Toast.LENGTH_SHORT).show();
}
SecondActivity
Intent i=getIntent();
i.putExtra("data","hi");
setResult(1,i);
finish();
Manifest
<activity
android:name=".FirstActivity"
android:windowSoftInputMode="adjustPan|stateAlwaysHidden"
android:theme="@style/MyMaterialTheme"
android:screenOrientation="portrait">
<intent-filter>
<data android:scheme="example"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:theme="@style/MyMaterialTheme"
android:windowSoftInputMode="adjustPan|stateAlwaysHidden"
android:screenOrientation="portrait">
</activity>
Upvotes: 0
Views: 730
Reputation: 650
You have to implement it by having a new object of intent and lastly finishing current activity.
Intent resultIntent = new Intent();
resultIntent.putExtra("data","hi");
setResult(Activity.RESULT_OK, resultIntent);
finish();
Hope this helps!
Upvotes: 0
Reputation: 10959
pass
setResult(Activity.RESULT_OK, i);
instead of
setResult(1,i);
Upvotes: 1
Reputation: 307
Change from :
Intent i=getIntent();
to:
Intent i=new Intent();// change this line
Upvotes: 4