Reputation: 4550
I have some project as a library named LibProj
. It has a lot of activities that I want to use in MainProj
project but I'm getting Activity Not Found error.
I have done these steps.
one of them is shown below.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("packagename//ex-com.hello",
"classname//ex-com.hello.ExampleActivity"));
startActivity(intent);
Second one is to add all activities' declarations in manifest of my MainProj
project.
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.doocat.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=".activity.main.IntroActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
</activity>
<activity
android:name=".activity.main.LoginActivity"
android:screenOrientation="portrait"
android:label="@string/app_name" />
<activity
etc...
Both of these ways not working. What I'm doing wrong or what is the solution?
Upvotes: 0
Views: 170
Reputation: 8939
Register Your Library Activity in MainProject manifest file..
I have given action name in intent-filter
com.lib.Example to identify which Activity need to call.
<activity
android:name="YOUR_LIBRARY_ACTIVITY_PACKAGE. ExampleActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.lib.Example" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Now call this Activity from your MainProject
Intent intent = new Intent("com.lib.Example");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
}
Hope This help you.
Upvotes: 1