活动没有指定父活动名称

时间:2015-03-24 20:12:33

标签: android android-fragments

我在menu.xml中有一个愿望清单。我点击wishlist菜单项,活动打开,但点击顶部的后退箭头。我收到以下错误:

 03-25 01:13:28.278: E/NavUtils(15464): getParentActivityIntent: bad parentActivityName 'com.ylg.link.Ylg_GridViewActivity' in manifest
 03-25 01:13:28.278: D/AndroidRuntime(15464): Shutting down VM
 03-25 01:13:28.278: W/dalvikvm(15464): threadid=1: thread exiting with uncaught exception (group=0x417c3700)
03-25 01:13:28.286: E/AndroidRuntime(15464): FATAL EXCEPTION: main
03-25 01:13:28.286: E/AndroidRuntime(15464): java.lang.IllegalArgumentException: Activity Ylg_Wishlist does not have a parent activity name specified. (Did you forget to add the android.support.PARENT_ACTIVITY <meta-data>  element in your manifest?)
03-25 01:13:28.286: E/AndroidRuntime(15464):    at android.support.v4.app.NavUtils.navigateUpFromSameTask(NavUtils.java:178)
03-25 01:13:28.286: E/AndroidRuntime(15464):    at com.ylg.link.Ylg_Wishlist.onOptionsItemSelected(YLG_Wishlist.java:47)
03-25 01:13:28.286: E/AndroidRuntime(15464):    at android.app.Activity.onMenuItemSelected(Activity.java:2566)
03-25 01:13:28.286: E/AndroidRuntime(15464):    at com.android.internal.widget.ActionBarView$3.onClick(ActionBarView.java:171)
03-25 01:13:28.286: E/AndroidRuntime(15464):    at android.view.View.performClick(View.java:4240)
03-25 01:13:28.286: E/AndroidRuntime(15464):    at android.view.View$PerformClick.run(View.java:17721)
03-25 01:13:28.286: E/AndroidRuntime(15464):    at android.os.Handler.handleCallback(Handler.java:730)
03-25 01:13:28.286: E/AndroidRuntime(15464):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-25 01:13:28.286: E/AndroidRuntime(15464):    at android.os.Looper.loop(Looper.java:137)
03-25 01:13:28.286: E/AndroidRuntime(15464):    at android.app.ActivityThread.main(ActivityThread.java:5103)
03-25 01:13:28.286: E/AndroidRuntime(15464):    at java.lang.reflect.Method.invokeNative(Native Method)
03-25 01:13:28.286: E/AndroidRuntime(15464):    at java.lang.reflect.Method.invoke(Method.java:525)
03-25 01:13:28.286: E/AndroidRuntime(15464):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
03-25 01:13:28.286: E/AndroidRuntime(15464):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-25 01:13:28.286: E/AndroidRuntime(15464):    at dalvik.system.NativeStart.main(Native Method)

请注意,Parent_Acitivty不是片段。我在FragmentActivity中有以下意图

        Intent intent = new Intent(this, Ylg_Wishlist.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);

当我点击后面的顶部按钮时,它应该指示我片段,但我得到了上述错误。

这是我宣布的清单:

        <activity
        android:name="com.ylg.link.Ylg_Wishlist"
        android:label="@string/wishlist"
        android:screenOrientation="portrait" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.ylg.link.Ylg_GridViewActivity" />
    </activity>  

有人可以帮我解决这个问题吗?如何调用后退按钮来调用片段而不是活动?

谢谢!

1 个答案:

答案 0 :(得分:0)

确保com.ylg.link.Ylg_GridViewActivity是活动而不是片段,您只能在android.support.PARENT_ACTIVITY元数据中指定活动。

另外,我发现清单中的名称为com.ylg.link.Ylg_GridViewActivity而堆栈跟踪中的com.ylg.link.ylg_GridViewActivity有点奇怪(在ylg_GridViewActivity中字母'Y'的情况不同)。它也可能与您的问题有关。