7

Possible Duplicate:
Android Launch an application from another application

I am having a problem and it is the following one:

I have two applications, and I want to launch one of the activities from one app by the other one......I am gonna give an example:

first app package:

"es.wul4.android.app1"

second app package:

"es.wul4.android.app2"

What I want is to launch the activity whose class is called "Identificar" from the app1

This activity is NOT the main one. I tried by doind that:

Intent intent = getPackageManager().getLaunchIntentForPackage("es.wul4.app2.Identificar");
startActivity(intent);

But what i get doing that is nothing, it tells me that the app doesn´t exists.

If i try doing that:

getPackageManager().getLaunchIntentForPackage("es.wul4.app2");
startActivity(intent);

And it launch one activity, but the main one........

How can I launch this particular Activity inside the package "es.wul4.app2.Identificar"??

Thank u very much.

Community
  • 1
  • 1
zapotec
  • 2,478
  • 4
  • 27
  • 47

3 Answers3

18

What you need to use are intent-filters. Assume the activity to be launched is in the package launch.me. Inside this applications manifest all the activities (main or otherwise) will be decalred by the <activity> tag.
Assuming the activity you want to launch is inside the class file Launchme. Then a portion of your manifest will be something like:

<activity android:name="launch.me.Launchme"
              android:label="@string/app_name">
<intent-filter>
            <action android:name="launch.me.action.LAUNCH_IT"/>
            <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>  

Now in the activity from where you want to launch the above activity use:(Note: This activity can be in any package anywhere. You have to make sure that both, the calling and the called packages are available on the device)

Intent i=new Intent();
i.setAction("launch.me.action.LAUNCH_IT");
startActivityForResult(i,0);

You can use other methods for starting the intent other than startActivityForResult, thats upto you.

Urban
  • 2,211
  • 23
  • 52
  • Thank you! I didn´t know it was neccesary to use the to launch the activity, now I can launch the activity without any problems and I even can send determinated data – zapotec Mar 23 '12 at 13:09
  • yes, you can easily pass values in between them by using `putExtra` with the intents :) – Urban Mar 23 '12 at 13:11
1

Did you add activity inside app1s manifest?:

    <activity
        android:label="@string/app_name"
        android:name=".Identificar" >
    </activity>
Caner
  • 49,709
  • 33
  • 153
  • 169
  • 1
    +1 for important thing is mentioned – Praveenkumar Mar 23 '12 at 12:35
  • 2
    .......I think you didn´t understand very well....app1 doesn´t contain Activity Identificar. The Activity Identificar is inside app2. What I want is to launch this activity from the app1. Thanks anyway. – zapotec Mar 23 '12 at 13:01
-3

I think, since both activities are in the same package that you only have to do:

startActivity(new Intent(getApplicationContext(), Identificar.class));
Marcos
  • 4,607
  • 7
  • 29
  • 57
  • read question again ... "first app package: `es.wul4.android.app1`, second app package: `es.wul4.android.app2`" – Selvin Mar 23 '12 at 12:37