7

I have this manifest:

<manifest ...
    package="com.my">

    <application ...>

        <activity ...
            android:name=".app.Run">
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    <activity ...
    android:name=".app.Preferences"/>

    <activity ...
    android:name=".library.error.ErrorDialog"/>

    </application>

</manifest>

How can I start ErrorDialog activity from Run activity?

Intent intent = new Intent();
intent.setComponent(new ComponentName("com.my.library.error", "com.my.library.error.ErrorDialog"));
startActivity(intent);

Or

Intent intent = new Intent();
intent.setComponent(new ComponentName("library.error", "library.error.ErrorDialog"));
startActivity(intent);

Not working


MEA CULPA... MEA CULPA...

My ErrorDialog Activity was not public. :D

Blo
  • 11,903
  • 5
  • 45
  • 99
user1993006
  • 79
  • 1
  • 1
  • 4

4 Answers4

9

1. Related to Application Manifest File

Manifest: 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
  package="app.run"/> 
<activity android:name="app.run"/> 
<activity android:name="library.error.ErrorDialog"/>

package app.run  // Your Main Application Package Name

Activity:
Intent i = new Intent(); 
i.setClassName("app.run", "library.error.ErrorDialog"); //
startActivity(i); 

setClassName()


2. Not related to Application Manifest File

Intent intent = new Intent();
intent.setComponent(new ComponentName("packagename whos activity u want to launch","classname.java"));   
startActivity(intent); 

setComponentName()

In your Case

Intent intent=new Intent();
intent.setComponent(new ComponentName("library.error", "library.error.ErrorDialog")); 
startActivity(intent);
Vikalp Patel
  • 10,669
  • 6
  • 61
  • 96
4

After creating two different applications(packages). Go to the manifest file of your first application and edit it as follows:--

<activity
android:name="com.example.applicationfire.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.application2.Second"
android:label="@string/app_name" >
</activity>

Here just declare the activity from the second application which you want to open from the first one. Please notice that here, "com.example.application2" is the package name of another application and "Second" is the name of the activity which is in the second package.

And the intent which you would fire for another activity in another application to start would be something like this --

btnStart.setOnClickListener(new OnClickListener() 
    {
        @Override
        public void onClick(View arg0) 
        {
            // TODO Auto-generated method stub
Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(new   ComponentName("com.example.application2","com.example.application2.Second"));
startActivity(intent);
}       });}

Now, here the first arguement which is passed into intent would be the package name of your second application and the second arguement would be the name of the activity to be opened. That's it. PS: Run the first app!

sonal
  • 41
  • 1
2

I fixed the issue with the Intent and setClass

Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClassName("packagewheretheactivityyouwantcallis", "packagewheretheactivityyouwantcallis.ActivityYouWantCall");
            startActivity(intent);

Don't forget to put into the Manifest of the activity you are writing the activity you want to call like this:

<application 
....>
 <activity
        android:name="packagewheretheactivityyouwantcallis.ActivityYouWantCall">
    </activity> 
</application>
Alexiscanny
  • 581
  • 7
  • 15
0

You can just use this code:

Intent myIntent= new Intent(FirstActivity.this,SecondActivity.class); 
startActivity(myIntent);

It doesn't make any diffirent if a class is in the same package of in another package. Just be sure you import the Class.

I used this code in my manifest:

<activity
    android:name="com.mycompany.mainapplication.package1.SecondActivity"
    android:label="Simple Math Questions" >
</activity>
ObAt
  • 2,337
  • 3
  • 24
  • 44