Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start activity from another package

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

like image 997
user1993006 Avatar asked Jan 20 '13 10:01

user1993006


1 Answers

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);
like image 101
Vikalp Patel Avatar answered Oct 30 '22 20:10

Vikalp Patel