Alex Rivera | Logout

Cannot start new Intent by setClassName with different package in Android

Asked 2012-03-29T10:31:20.847
13

I want to start a new Intent dynamically. Therefore setClassName seems the best choice.

First, I define 3 activity in Manifest

<activity android:name="com.example.pkg2.Act" />
<activity android:name="com.example.pkg1.Act1" />
<activity android:name="com.example.pkg1.Act2" />

From com.example.pkg2.Act:

Intent intent = new Intent();
if(index == 0) intent.setClassName(Act.this, "com.example.pkg1.Act1");
else intent.setClassName(Act.this, "com.example.pkg1.Act2");
startActivity(intent);

And will get this exception:

Unable to find explicit activity class {com.example.pkg2.Act/com.example.pkg1.Act1}; have you declared this activity in your AndroidManifest.xml?

It looks like we can only use setClassName to dynamically start new Activity but within the same package.

Any idea to solve this issue? All help is appreciated.

Edit
Report

1 Answer

0

Follow the syntax to write setClassName() method:

 setClassName( pkgName, className ) 
answered 2012-03-29T10:36:47.707

Your Answer