tags:

views:

390

answers:

2

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>

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

+2  A: 

You start new Activities via Intents.

See this documentation.

Specificially to start your Activity A from Activity B you would use something like the following in your Activity B class:

this.startActivity(new Intent(this, com.example.MyExampleActivity.class));
mbaird
A: 

Hi mbaird, 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);
Sorry, didn't think about the classes being in different apps. I was mainly trying to point you toward Intents.
mbaird