tags:

views:

260

answers:

2

I have activity A in package one, and I want to run an intent which will up an activity B which is in package two.

How can I do this? Any samples will be welcome.

this is what ive done, and the error i get:

first activity ("MainActivity") in a package: com.abelski.currencyclient and second activity("SecondActivity" in a diffrent package: com.idan.second

now i wanna call from MainActivity to SecondActivity.

ive added this line at the manifest of the MainActivity:

now in main Activity i got this button which run this line:

Intent intent = new Intent(MainActivity.this,SecondApplicationActivity.class);

and this is the rror:

04-29 09:20:59.197: ERROR/AndroidRuntime(399): Uncaught handler: thread main exiting due to uncaught exception 04-29 09:20:59.276: ERROR/AndroidRuntime(399): java.lang.NoClassDefFoundError: com.idan.second.SecondApplicationActivity 04-29 09:20:59.276: ERROR/AndroidRuntime(399):
...

thanks for help.

+1  A: 

Use explicit intents:

Intent intent = new Intent(context,ClassName.class);

where ClassName is from another package.

Sometimes, you will not know the name of the class in such cases you will have to rely on the Intent that the target class advertises to handle.

Samuh
it didnt work, please check my question again, ive edited it.
rayman
A: 

I am assuming that by "packages" you mean applications.

We have: - ApplicationA with FirstActivity - ApplicationB with SecondActivity

If, in the ApplicationB's AndroidManifest.xml file, in the declaration of SecondActivity you add an intent filter such as:

<activity android:name=".SecondActivity">
  <intent-filter>
    <action android:name="applicationB.intent.action.Launch" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</activity>

You can create an Intent to launch this SecondActivity from the FirstActivity with:

Intent intent = new Intent("applicationB.intent.action.Launch");
startActivity(intent);

What this all means is:

  • The SecondActivity has a filter for the intent action of "applicationB.intent.action.Launch"
  • When you create an intent with that action and call 'startActivity' the system will find the activity (if any) that responds to it

The documentation for this is at: http://developer.android.com/intl/zh-TW/reference/android/content/Intent.html

rcabaco
Thanks for your help.
rayman
Tell me you think there is a way to launch this application without gui? just to launch it to the background?
rayman
I think you should a service for that. You can check the documentation at: http://developer.android.com/intl/zh-TW/reference/android/app/Service.html
rcabaco