onActivityResult不android系统的工作原理工作原理、系统、onActivityResult、android

2023-09-12 05:08:08 作者:爛人

我有一个主要的活动被称为主要有onActivityResult方法。

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); 

}

和我的第二个活动,我写了code按钮动作。

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();
    }

所以,现在的问题是,当第二个动作结束。 onActivityResult并不在主要活动叫......有谁能够告诉我,我错了。

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);
        }

和这里是我的menifest文件

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.

推荐答案

您两项活动必须在相同的任务...

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

中有你的android定义singleTask:launchMode

Have you define "singleTask" in android:launchMode ?