Student
Student

Reputation: 28345

How do I start my app from my other app?

How do I start my app from my other app? (they will not be package together)

--update

Manifest of the second app:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.helloandroid"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HelloAndroid"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.HOME"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>

        <activity android:name=".HelloAndroid">
            <intent-filter>
                <action android:name="com.example.helloandroid.HelloAndroid" />
            </intent-filter>
        </activity>

    </application>


</manifest>

I calling it with:

startActivity(new Intent("com.example.helloandroid.HelloAndroid"));

and it throws:

07-16 15:11:01.455: ERROR/Desktop(610): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.helloandroid.HelloAndroid }

Ralated:
How to launch android applications from another application

Upvotes: 1

Views: 3161

Answers (2)

Rasmus
Rasmus

Reputation: 554

This questions seems similar to one I answered earlier today.

If you just want to start like you started it from the launcher:

Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(new ComponentName( "PACKAGE NAME", "CLASS" ));
startActivity(intent);

Upvotes: 1

Cristian
Cristian

Reputation: 200090

In the first app, you will have to modify the AndroidManifest.xml. Specifically, you are going to add a custom action into the intent-filter of the activity that you want to launch from somewhere:

<activity android:name="FirstApp">
  <intent-filter>
    <action android:name="com.example.foo.bar.YOUR_ACTION" />
  </intent-filter>
</activity>

Then, in your second app you use that action to start the activity:

startActivity(new Intent("com.example.foo.bar.YOUR_ACTION"));

With regards to your comments:

Looks like if I change the default name "android.intent.action.MAIN" I'm not able to run the app from the Eclipse in the Virtual Device

Keep in mind you can have as many actions as you want... for instance:

<activity android:name="FirstApp">
  <intent-filter>
    <action android:name="com.example.foo.bar.YOUR_ACTION" />
    <action android:name="android.intent.action.MAIN" />
  </intent-filter>
</activity>

Upvotes: 4

Related Questions