OnActivityResult Doesn't work in android

I have a main Main action that has an onActivityResult method.

protected void onActivityResult(int requestCode, int resultCode, Intent data, Bundle extras) { Log.i("in OnActivityResult", "in OnActivityResult"); super.onActivityResult(requestCode, resultCode, data); Log.i("in OnActivityResult", "in OnActivityResult"); ObjectInputStream ois = null; if(requestCode == SUB_ACTIVITY_REQUEST_CODE) { Log.i("in OnActivityResult IFFFF", "in OnActivityResult IFFFF"); extras = getIntent().getExtras(); byte gpBytes[] = extras.getByteArray("gpBytes"); ByteArrayInputStream bis = new ByteArrayInputStream(gpBytes); try { ois = new ObjectInputStream(bis); gpObject = (GP) ois.readObject(); } catch (StreamCorruptedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Log.i("GP object Values", "GP object Values<<>>"+ this.gpObject.xValue + "and <<>>" + this.gpObject.yValue); } 

and in my second action I wrote this code on the Action button.

 public void onClick(View v) { Log.i("button", "button"); goToGrifReferenceAction(); GridReferenceActivity.this.setResult(RESULT_OK, getIntent().putExtra("gpObject", GridReferenceActivity.this.gpBytes)); GridReferenceActivity.this.finish(); } 

so now the problem is when the second action ends. onActivityResult does not call in the main activity ... can someone tell me where I am going wrong.

and I invoke the second action as follows.

 @Override public void onClick(View v) { Intent i = new Intent(Main.this, GridReferenceActivity.class); startActivityForResult(i, SUB_ACTIVITY_REQUEST_CODE); } 

and here is my manifest file

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.anquetMap" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable = "true"> <activity android:name=".Main" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation" android:launchMode="singleTask"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".GridReferenceActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.GridReferenceActivity"/> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="7" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

I will be very grateful to him. Many thanks.

+1
android android-activity
source share
3 answers

Your two actions should be in the same task ...

Do you define "singleTask" in android: launchMode?

+4
source share

How do you start the second action, you use

startActivity (intent)

or

startActivityForResult (intent intention, int requestCode)

You have to use

 Intent intent = new Intent(this, SecondActivity.class); startActivityForResult(intent, SUB_ACTIVITY_REQUEST_CODE); 
0
source share

I just used the three argument methods protected void onActivityResult (int requestCode, int resultCode, Intent data) {}

and he worked.

0
source share

All Articles