Bug 15914 - Getting exception Java.Lang.IllegalArgumentException: Activity SecondActivity does not have a parent activity name specified even though it is specified.
Summary: Getting exception Java.Lang.IllegalArgumentException: Activity SecondActivity...
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.8.x
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2013-11-04 16:18 UTC by Jon Goldberger [MSFT]
Modified: 2013-11-04 17:08 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Test Project (501.17 KB, application/zip)
2013-11-04 16:19 UTC, Jon Goldberger [MSFT]

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Comment 1 Jon Goldberger [MSFT] 2013-11-04 16:19:22 UTC
Created attachment 5329 [details]
Test Project
Comment 2 Jon Goldberger [MSFT] 2013-11-04 16:20:33 UTC
I am having trouble getting my app to navigate up from one Activity to
another. I am using the V4 support library and
NavUtils.NavigateUpFromSameTask(...). When I am trying to do this I get an
errror (see below).

Java.Lang.IllegalArgumentException: Activity SecondActivity does not have a parent activity name specified. (Did you forget to add the android.support.PARENT_ACTIVITY <meta-data>  element in your manifest?)
  at Android.Runtime.JNIEnv.CallStaticVoidMethod (intptr,intptr,Android.Runtime.JValue[]) [0x00023] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:973
  at Android.Support.V4.App.NavUtils.NavigateUpFromSameTask (Android.App.Activity) [0x00050] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid-bindings/Compatibility-v4/bindings/obj/platform-18/src/generated/Android.Support.V4.App.NavUtils.cs:588
  at OptionsMenu.SecondActivity.OnOptionsItemSelected (Android.Views.IMenuItem) [0x00012] in d:\tmp\OptionsMenu\OptionsMenu\SecondActivity.cs:46
  at Android.App.Activity.n_OnOptionsItemSelected_Landroid_view_MenuItem_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid/src/Mono.Android/platforms/android-18/src/generated/Android.App.Activity.cs:3039
  at at (wrapper dynamic-method) object.d23ee9ca-846c-4ebb-8e54-1c2d8cce550d (intptr,intptr,intptr) <IL 0x00017, 0x0004b>
  at --- End of managed exception stack trace ---
  at java.lang.IllegalArgumentException: Activity SecondActivity does not have a parent activity name specified. (Did you forget to add the android.support.PARENT_ACTIVITY <meta-data>  element in your manifest?)
  at 	at android.support.v4.app.NavUtils.navigateUpFromSameTask(NavUtils.java:177)
  at 	at optionsmenu.SecondActivity.n_onOptionsItemSelected(Native Method)
  at 	at optionsmenu.SecondActivity.onOptionsItemSelected(SecondActivity.java:46)
  at 	at android.app.Activity.onMenuItemSelected(Activity.java:2548)
  at 	at com.android.internal.widget.ActionBarView$3.onClick(ActionBarView.java:168)
  at 	at android.view.View.performClick(View.java:4202)
  at 	at android.view.View$PerformClick.run(View.java:17340)
  at 	at android.os.Handler.handleCallback(Handler.java:725)
  at 	at android.os.Handler.dispatchMessage(Handler.java:92)
  at 	at android.os.Looper.loop(Looper.java:137)
  at 	at android.app.ActivityThread.main(ActivityThread.java:5039)
  at 	at java.lang.reflect.Method.invokeNative(Native Method)
  at 	at java.lang.reflect.Method.invoke(Method.java:511)
  at 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  at 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  at 	at dalvik.system.NativeStart.main(Native Method)
Comment 3 Jonathan Pryor 2013-11-04 17:08:33 UTC
The problem is due to an "activity name mismatch". For example, this is part of the generated AndroidManifest.xml file:

    <activity android:name=".SecondActivity" android:label="@string/app_name">
      <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity" />
    <activity android:label="SecondActivity" android:name="optionsmenu.SecondActivity" />

Notice that there are _two_ "SecondActivity" <activity/> elements. Furthermore, the first one _does not exist_, because (by Android convention) it's constructed by appending the //activity/@android:name attribute value to the /manifest/@package value, i.e. it's looking for the type `OptionsMenu.OptionsMenu.SecondActivity`, which doesn't exist.

In general, please use custom attributes instead of editing Properties\AndroidManifest.xml (unless there are no applicable custom elements, e.g. for Java-provided activities):



    [Activity (Label = "SecondActivity")]            
    [MetaData ("android.support.PARENT_ACTIVITY", Value=".MainActivity")]
    public partial class SecondActivity : Activity {

This generates the desired XML and removes the exception:

    <activity android:label="SecondActivity" android:name="optionsmenu.SecondActivity">
      <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity" />
    <!-- no other SecondActivity elements -->