views:

99

answers:

3

hello guys,

i have a main Activity called Main which has 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 activity i wrote that code on button Action.

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 problem is when the second activity finishes. onActivityResult does not call in main activity... can anybody tell me where i am going wrong.

and i am calling the second activity like this.

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

and here is my menifest 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'll be very thankful to him. Thanks a lot.

A: 

How do you start the second activity are you using

startActivity(intent)

or

startActivityForResult(Intent intent, int requestCode)

You should use

Intent intent = new Intent(this, SecondActivity.class);
startActivityForResult(intent, SUB_ACTIVITY_REQUEST_CODE);
madsleejensen
yea i am using StartActivityForResult(i, requestCode); but still it does not work.
sajjoo
A: 

Your two activities must be in the same task...

Have you define "singleTask" in android:launchMode ?

GBouerat
yes i did but still not working.
sajjoo
remove singleTask
GBouerat
if you set singleTask you can't use startActivityForResult() beacuse your activities will not be in the same task
GBouerat
A: 

i just used three argument method protected void onActivityResult(int requestCode, int resultCode, Intent data){}

and it worked.

sajjoo