Android 使用ResultOfActivity从其他应用程序启动并获取字符串值
我在android中有两个应用程序:应用程序1和应用程序2,从我的应用程序1中,我想调用应用程序2执行一些活动,并使用活动结果返回字符串值。现在我的问题是,我已经执行了从我的应用程序1调用应用程序2的操作,但是从我的on Result活动中,当应用程序2完成时,我的应用程序1没有返回任何值。请帮助我成为优秀的程序员。谢谢 我的App1代码:Android 使用ResultOfActivity从其他应用程序启动并获取字符串值,android,Android,我在android中有两个应用程序:应用程序1和应用程序2,从我的应用程序1中,我想调用应用程序2执行一些活动,并使用活动结果返回字符串值。现在我的问题是,我已经执行了从我的应用程序1调用应用程序2的操作,但是从我的on Result活动中,当应用程序2完成时,我的应用程序1没有返回任何值。请帮助我成为优秀的程序员。谢谢 我的App1代码: private void btnVerify() { // TODO Auto-generated method stub
private void btnVerify() {
// TODO Auto-generated method stub
ImageButton verify = (ImageButton) findViewById(R.id.imageButton1);
verify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(VoteActivity.this, "Verifying Camera Loading..", Toast.LENGTH_LONG).show();
PackageManager pm = getPackageManager();
Intent i = pm.getLaunchIntentForPackage("org.opencv.samples.fd");
startActivityForResult(i, 0);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK) {
Bundle res = data.getExtras();
resv = (String) res.get("regid");
// Toast.makeText(getApplicationContext(), "TEST1"+resv, Toast.LENGTH_SHORT).show();
}
}
我的应用程序2代码:
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
vname = mView.saveValues(aw);
Intent person = new Intent();
Bundle backpack = new Bundle();
backpack.putString("regid",vname);
person.putExtras(backpack);
setResult(RESULT_OK,person);
finish();
}
});
应用程序1 android清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.votingapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".VoteActivity"
android:label="@string/title_activity_vote" >
</activity>
<activity
android:name=".RegActivity"
android:label="@string/title_activity_reg" >
</activity>
<activity
android:name=".VerifyActivity"
android:label="@string/title_activity_verify" >
</activity>
<activity
android:name=".Verification"
android:label="@string/title_activity_verification" >
</activity>
</application>
</manifest>
应用程序2 Android清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.opencv.samples.fd"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />
<supports-screens android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application android:label="@string/app_name" android:icon="@drawable/icon">
<activity android:name="FdActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
</manifest>
onActivityResult包中的res不为空?谢谢您的回复,先生。。先生,请帮帮我。当我烤面包的时候。它没有发挥作用。我的如果函数onResultActivity中的条件未执行onactivityresult是否被触发?添加log.vtag,值以查看它是否触发。如何记录onactivityresult。。如果resultcode==RESULT\u OK{Bundle res=data.getExtras;resv=String res.getregid;toast.makeTextgetApplicationContext,TEST1+resv,toast.LENGTH\u SHORT.show;}我试图对它进行toast,但它没有执行,而是使用logcat显示toast,将其放在activityresult>Log.dACTIVITYNAME中,正在调用Getting result,其值为:+resv;然后观察logcat,看看它是否已打印