Java 使用intent在两个android应用程序之间传递数据

Java 使用intent在两个android应用程序之间传递数据,java,android,android-intent,Java,Android,Android Intent,我有两个独立的android应用程序,AppA和AppB。我正试图让AppA启动AppB(这是一款游戏应用程序)。用户玩完游戏(AppB)后,会将游戏记录发送回AppA 因此,AppA正确启动了AppB,但当用户玩完游戏(AppB)后,AppB在将数据发送回AppA时崩溃,出现以下错误: 进程:com.joy.AppB,PID:20265 android.content.ActivityNotFoundException:找不到显式活动类{com.joy.AppA/com.joy.AppA.vi

我有两个独立的android应用程序,AppA和AppB。我正试图让AppA启动AppB(这是一款游戏应用程序)。用户玩完游戏(AppB)后,会将游戏记录发送回AppA

因此,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
活动类名: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>
<?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>
.
.
.
    <?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="com.joy.AppA.views.activities.LAUNCH_IT" />
            <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".views.activities.DashboardActivity" />

        </activity>
AppB的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>
<?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>
.
.
.
    <?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="com.joy.AppA.views.activities.LAUNCH_IT" />
            <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".views.activities.DashboardActivity" />

        </activity>

.
.
.
提前感谢您的帮助

试试这个:

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>
<?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>
.
.
.
    <?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="com.joy.AppA.views.activities.LAUNCH_IT" />
            <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".views.activities.DashboardActivity" />

        </activity>

也许它会有用:

内容提供程序和内容解析程序组件

内容解析器向内容提供者发出请求,提供者作出响应。这类似于两个不同应用程序之间的通信

例如,客户端(解析器)和内容管理器(提供者)

这是一个示例教程:


希望有帮助

谢谢你的帮助!我想问一下,您是否知道如何让AppA从AppB接收多个字符串数组?目前,AppB一次向AppA发送多个字符串数组,但AppA仅从区块接收第一个字符串数组。谢谢@我很高兴我的回答对你有帮助。如果正确理解您的评论问题,您希望向活动?发送不同的数组?。您可以这样做:
Intent i=newintent();i、 setAction(“com.joy.AppA.views.activities.LAUNCH_IT”);i、 putExtra(“gameRecordArray1”,gameRecord_数组);i、 putExtra(“gameRecordArray2”,gameRecord_数组);i、 putExtra(“gameRecordArray3”,gameRecord_数组);i、 putExtra(“gameRecordArray4”,gameRecord_数组);星触觉(i)