2010-07-15 151 views
0

如何從我的其他應用程序啓動我的應用程序? (它們將不被一起打包)如何從我的其他應用程序啓動我的應用程序?

--update

清單第二應用的:

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

Ralated:
How to launch android applications from another application

回答

4

在第一個應用程序,你將不得不修改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")); 

至於您的評論:

看起來像如果我更改默認名稱「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> 
+0

看起來像如果我更改默認名稱「android.intent.action.MAIN」我不能夠運行應用程序來自虛擬設備中的Eclipse。我可以將它作爲獨立應用程序在手機上運行嗎? – 2010-07-16 14:08:44

+0

按照你的說法並且正在丟擲: android.content.ActivityNotFoundException:找不到處理Intent的動作{act = com.example.helloandroid.HelloAndroid}。任何想法可能是錯的? (現在我添加了一個新的活動,而不是改變現有的) – 2010-07-16 14:23:15

+0

我編輯了我的答案。此外,我希望看到您的AndroidManifest第一個應用,以及第二個活動的源代碼。 – Cristian 2010-07-16 14:45:06

1

這個問題似乎類似於一個我前面today回答。

如果你只是想開始喜歡你從啓動開始吧:

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

與上一個答案相同,在最後加上一個問題:「android.content.ActivityNotFoundException:無法找到顯式活動類{com.example.helloandroid/HelloAndroid};你是否在你的AndroidManifest.xml中聲明瞭這個活動?」 – 2010-07-16 18:06:31

相關問題