I'm getting exception
12-12 17:31:18.401: E/AndroidRuntime(18177): FATAL EXCEPTION: main
12-12 17:31:18.401: E/AndroidRuntime(18177): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.testalias.sp/com.example.testalias.sp.SecondActivity}; have you declared this activity in your AndroidManifest.xml?
12-12 17:31:18.401: E/AndroidRuntime(18177): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1635)
12-12 17:31:18.401: E/AndroidRuntime(18177): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1434)
12-12 17:31:18.401: E/AndroidRuntime(18177): at android.app.Activity.startActivityForResult(Activity.java:3430)
12-12 17:31:18.401: E/AndroidRuntime(18177): at android.app.Activity.startActivityForResult(Activity.java:3391)
12-12 17:31:18.401: E/AndroidRuntime(18177): at android.app.Activity.startActivity(Activity.java:3626)
12-12 17:31:18.401: E/AndroidRuntime(18177): at android.app.Activity.startActivity(Activity.java:3594)
12-12 17:31:18.401: E/AndroidRuntime(18177): at com.example.testalias.AliasTestActivity$2.onClick(AliasTestActivity.java:40)
12-12 17:31:18.401: E/AndroidRuntime(18177): at android.view.View.performClick(View.java:4354)
12-12 17:31:18.401: E/AndroidRuntime(18177): at android.view.View$PerformClick.run(View.java:17961)
12-12 17:31:18.401: E/AndroidRuntime(18177): at android.os.Handler.handleCallback(Handler.java:725)
12-12 17:31:18.401: E/AndroidRuntime(18177): at android.os.Handler.dispatchMessage(Handler.java:92)
12-12 17:31:18.401: E/AndroidRuntime(18177): at android.os.Looper.loop(Looper.java:137)
12-12 17:31:18.401: E/AndroidRuntime(18177): at android.app.ActivityThread.main(ActivityThread.java:5328)
12-12 17:31:18.401: E/AndroidRuntime(18177): at java.lang.reflect.Method.invokeNative(Native Method)
12-12 17:31:18.401: E/AndroidRuntime(18177): at java.lang.reflect.Method.invoke(Method.java:511)
12-12 17:31:18.401: E/AndroidRuntime(18177): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
12-12 17:31:18.401: E/AndroidRuntime(18177): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
12-12 17:31:18.401: E/AndroidRuntime(18177): at dalvik.system.NativeStart.main(Native Method)
My manifest code
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.testalias.AliasTestActivity"
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=".sp.SecondActivity"
android:label="@string/app_name" >
</activity>
</application>
And my code
btn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent1 = new Intent();
intent1.setComponent(new ComponentName("com.example.testalias.sp", "com.example.testalias.sp.SecondActivity"));
startActivity(intent1);
}
});
May be I have done this at least thousand times, but don't know why not able to do now. Please help me.
Try this..
You can use your code same like it is. just change the package name inside your
ComponentName
com.example.testalias.sp
tocom.example.testalias
and try again