如何启动另一个应用程序中的活动?应用程序

2023-09-12 00:12:24 作者:迷人的妖孽

我已经应用程序中的定义如下:

I have application A defined as below:

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name="com.example.MyExampleActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

现在的应用程序B,我怎么能写code,开始在应用程序中的活动?谢谢!

Now in application B, how can I write the code to start the activity in application A? Thanks!

推荐答案

感谢您为您回复。你解决方案仅适用于两个活动是在同一应用程序。就我而言,应用程序B不知道类com.example.MyExampleActivity.class在code,因此编译会失败。

thank you for you reply. You solution only works for two activities that are in the same application. In my case, application B doesn't know class com.example.MyExampleActivity.class in the code, so compile will fail.

我在网上搜索,并发现了一些类似这样的下方,它工作得很好。

I searched on the web and found something like this below, and it works well.

Intent intent = new Intent();
intent.setComponent(new ComponentName("com.example", "com.example.MyExampleActivity"));
startActivity(intent);