tags:

views:

92

answers:

2

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:
http://stackoverflow.com/questions/1605074/how-to-launch-android-applications-from-another-application

+2  A: 

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>
Cristian
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. Will I be able to run it on the phone as a standalone app?
Tom Brito
Did as you say, and is throwing:android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.helloandroid.HelloAndroid }. Any idea what may be wrong? (now I added a new activity instead of changind the existing)
Tom Brito
I have edited my answer. Also, I'd like to see the AndroidManifest of you first app, and the source code of your second activity.
Cristian
I updated my question with the source, take a look..
Tom Brito
Nice! I was putting my action in the wrong place, as you can see in my update to the question.. Thanks!
Tom Brito
Additionally, the app that will be called **need** to have in the manifest, inside the intent-filter element: <category android:name="android.intent.category.DEFAULT"/>
Tom Brito
A: 

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);
Rasmus
same of the previous answer, with a plus question in the final: "android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.helloandroid/HelloAndroid}; have you declared this activity in your AndroidManifest.xml?"
Tom Brito