我有两个独立的android应用程序AppA和AppB。我正试图让AppA启动AppB(这是一款游戏应用程序)。用户完成游戏(AppB)后,它会将游戏记录发送回AppA。使用意图在两个android应用程序之间传递数据
所以,APPA是正确开展APPB,但是当用户使用玩游戏(APPB)来完成,APPB崩溃,当发送数据回APPA,而这个错误显示出来:
过程:COM .joy.AppB,PID:20265 android.content.ActivityNotFoundException:无法找到显式活动类{com.joy.AppA/com.joy.AppA.views.activities.StartGameActivity};你有没有在你的AndroidManifest.xml中声明这个活动?
APPA包名称:com.joy.AppA
Activity类名:com.joy.AppA.views.activities.StartGameActivity
APPB包名称:com.joy.AppB
活动类名:com.joy.AppB.MainActivity
以下是我迄今所做的:
APPA的StartGameActivity:
//To launch AppB game
Intent launchGameIntent = getPackageManager().getLaunchIntentForPackage("com.joy.AppB");
startActivity(launchGameIntent);
//To retrieve game scores from AppB game
Intent intent = getIntent();
String[] gameRecords_array = intent.getStringArrayExtra("gameRecord");
APPA的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.joy.AppA">
.
.
.
<activity
android:name="com.joy.AppA.views.activities.StartGameActivity"
android:label="Start Game">
<intent-filter>
<action android:name="android.intent.action.SEND" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".views.activities.DashboardActivity" />
</activity>
APPB的MainActivity:
Intent i = new Intent();
i.setComponent(new ComponentName("com.joy.AppA","com.joy.AppA.views.activities.StartGameActivity"));
i.setAction(Intent.ACTION_SEND);
i.putExtra("gameRecord", gameRecord_array);
startActivity(i);
APPB的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.joy.AppB" >
<supports-screens android:resizeable="true" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
.
.
.
预先感谢您帮帮我!
感谢您的帮助!就像询问您是否知道如何让AppA从AppB接收多个字符串数组?目前AppB一次向AppA发送多个字符串数组,但AppA只接收来自该块的第一个字符串数组。谢谢! – unintendedjoy
@unintendedjoy,很高兴我的回答对你有所帮助。如果正确理解你的评论问题,你想发送不同的阵列到活动?你可以这样做: 'Intent i = new Intent(); i.setAction(“com.joy.AppA.views.activities.LAUNCH_IT”); i.putExtra(“gameRecordArray1”,gameRecord_array); i.putExtra(“gameRecordArray2”,gameRecord_array); i.putExtra(“gameRecordArray3”,gameRecord_array); i.putExtra(“gameRecordArray4”,gameRecord_array); startActivity(i);' –
其实,我的意思是这样,你可以看到我发布的这个问题:[使用意图在两个应用程序之间传递多个字符串数组](http://stackoverflow.com/questions/42533566/passing -multiple-string-arrays-between-apps-using-intent?noredirect = 1#comment72202953_42533566)谢谢! – unintendedjoy