【问题标题】:How do I start my app from my other app?如何从我的其他应用程序启动我的应用程序?
【发布时间】:2010-07-17 02:11:36
【问题描述】:

如何从我的其他应用启动我的应用? (不会打包在一起)

--更新

第二个应用的清单:

<?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>

我叫它:

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

它抛出:

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

相关:
How to launch android applications from another application

【问题讨论】:

    标签: android


    【解决方案1】:

    在第一个应用程序中,您必须修改AndroidManifest.xml。具体来说,您要将自定义action 添加到要从某处 启动的活动的intent-filter 中:

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

    然后,在您的第二个应用中,您使用该操作来启动活动:

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

    关于您的 cmets:

    看起来如果我更改默认名称“android.intent.action.MAIN”,我将无法从虚拟设备中的 Eclipse 运行应用程序

    请记住,您可以根据需要执行任意数量的操作...例如:

    <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>
    

    【讨论】:

    • 看起来如果我更改默认名称“android.intent.action.MAIN”,我将无法从虚拟设备中的 Eclipse 运行应用程序。我可以在手机上作为独立应用运行它吗?
    • 照你说的做了,并且正在抛出:android.content.ActivityNotFoundException:没有找到处理 Intent { act=com.example.helloandroid.HelloAndroid } 的活动。知道可能出了什么问题吗? (现在我添加了一个新活动而不是更改现有活动)
    • 我已经编辑了我的答案。另外,我想看看你的第一个应用程序的 AndroidManifest,以及你的第二个活动的源代码。
    • 不错!正如您在我对问题的更新中看到的那样,我将操作放在了错误的位置。谢谢!
    • 此外,将被调用的应用需要在清单中,intent-filter 元素内:
    【解决方案2】:

    这个问题似乎与我之前回答的问题 today 相似。

    如果您只是想像从启动器启动它一样开始:

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

    【讨论】:

    • 与上一个答案相同,最后一个加号问题:“android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.helloandroid/HelloAndroid}; 你声明了这个活动吗在你的 AndroidManifest.xml 中?”
    最近更新 更多