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="androi开发者_运维技巧d.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 applicationIn 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>
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);
精彩评论