gpt4 book ai didi

android - ActionBar 后退按钮 StackTrace 错误

转载 作者:行者123 更新时间:2023-11-29 01:42:01 25 4
gpt4 key购买 nike

借助这些 Navigation with Action Bar .我尝试创建一个操作栏后退按钮。

后退按钮显示在输出中。但是如果我单击后退按钮,则堆栈跟踪错误发生在一次。

堆栈跟踪:

 E/AndroidRuntime(1846): FATAL EXCEPTION: main
E/AndroidRuntime(1846): Process: com.fth.android, PID: 1846
E/AndroidRuntime(1846): java.lang.IllegalArgumentException: Activity HomeActivity does not have a parent activity name specified. (Did you forget to add the android.support.PARENT_ACTIVITY <meta-data> element in your manifest?)
E/AndroidRuntime(1846): at android.support.v4.app.NavUtils.navigateUpFromSameTask(NavUtils.java:177)
E/AndroidRuntime(1846): at com.sit.fth.activity.HomeActivity.onOptionsItemSelected(HomeActivity.java:160)
E/AndroidRuntime(1846): at android.app.Activity.onMenuItemSelected(Activity.java:2600)
E/AndroidRuntime(1846): at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
E/AndroidRuntime(1846): at com.android.internal.widget.ActionBarView$3.onClick(ActionBarView.java:167)
E/AndroidRuntime(1846): at android.view.View.performClick(View.java:4438)
E/AndroidRuntime(1846): at android.view.View$PerformClick.run(View.java:18422)
E/AndroidRuntime(1846): at android.os.Handler.handleCallback(Handler.java:733)
E/AndroidRuntime(1846): at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime(1846): at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(1846): at android.app.ActivityThread.main(ActivityThread.java:5017)
E/AndroidRuntime(1846): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(1846): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(1846): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime(1846): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/AndroidRuntime(1846): at dalvik.system.NativeStart.main(Native Method)

list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fth.android"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />

<application
android:name="com.sit.fth.app.GemsApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@android:style/Theme.Holo.Light" >

<activity
android:name="com.sit.fth.activity.SplashActivity"
android:parentActivityName="com.sit.fth.activity.HomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.sit.fth.activity.HomeActivity" />

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.sit.fth.activity.HomeActivity"
android:screenOrientation="portrait" >
</activity>
<activity android:name="com.sit.fth.activity.YoutubePlayActivity" >
</activity>
</application>

</manifest>

HomeActivity.java:

package com.sit.fth.activity;

public class HomeActivity extends BaseActivity implements
VideoFragment.OnVideoSelectedListener,

AboutFragment.OnAboutFragmentSelectedListener,

AnnouncenentFragment.OnAnnouncementSelectedListener,

GalleryFragment.OnGalItemSelectedListener,

MagzineFragment.OnMagzineSelectedListener {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this); // 160 th line Error
return true;
}
return super.onOptionsItemSelected(item);
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@SuppressLint("NewApi")
public boolean onOptionsItemSelected1(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {

TaskStackBuilder.create(this)
.addNextIntentWithParentStack(upIntent)
.startActivities();
} else {
NavUtils.navigateUpTo(this, upIntent);
}
return true;
}
return super.onOptionsItemSelected(item);
}

我不知道如何解决这些问题。任何人都可以帮助我解决这些问题。谢谢。

最佳答案

java.lang.IllegalArgumentException: Activity HomeActivity does not have a parent activity name specified. (Did you forget to add the android.support.PARENT_ACTIVITY element in your manifest?)

您需要在 list 中提及 Home Activity 的父 Activity

http://developer.android.com/training/implementing-navigation/ancestral.html

关于android - ActionBar 后退按钮 StackTrace 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23990652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com