uni*_*joy 6 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.views.activities.StartGameActivity};您是否在 AndroidManifest.xml 中声明了此活动?
AppA包名称:com.joy.AppA
Activity类名称:com.joy.AppA.views.activities.StartGameActivity
AppB包名称:com.joy.AppB
Activity类名称: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");
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
AppB 的主要活动:
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);
Run Code Online (Sandbox Code Playgroud)
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>
.
.
.
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助!
尝试这个:
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="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>
Run Code Online (Sandbox Code Playgroud)
然后要将数据从应用程序 b 发送到应用程序 a 活动,请执行以下操作:
Intent i = new Intent();
i.setAction("com.joy.AppA.views.activities.LAUNCH_IT");
i.putExtra("gameRecord", gameRecord_array);
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4412 次 |
| 最近记录: |