本文介绍了回到父活动在清单父活动错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是清单code相关的主题:

This is the manifest code related to the subject:

   <activity
        android:name="smartHomes.capstone.GeneralAndSecurity"
        android:label="@string/title_activity_general_and_security"
        android:parentActivityName="smartHomes.capstone.HomePage" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="smartHomes.capstone.HomePage" />
    </activity>

这是错误日志:

   03-20 21:19:18.227: E/AndroidRuntime(787): FATAL EXCEPTION: main
   03-20 21:19:18.227: E/AndroidRuntime(787): java.lang.IllegalArgumentException: Activity           GeneralAndSecurity 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-20 21:19:18.227: E/AndroidRuntime(787):   at android.support.v4.app.NavUtils.navigateUpFromSameTask(NavUtils.java:177)
   03-20 21:19:18.227: E/AndroidRuntime(787):   at smartHomes.capstone.GeneralAndSecurity.onOptionsItemSelected(GeneralAndSecurity.java:41)
   03-20 21:19:18.227: E/AndroidRuntime(787):   at com.actionbarsherlock.app.SherlockActivity.onMenuItemSelected(SherlockActivity.java:208)

请可我知道为什么返回了按钮返回我的错误?

Please can i know why is the return up button returning me an error?

推荐答案

没有相同的工作对我来说的元数据

The same worked for me without meta-data

下面是我的榜样。

    <activity android:name="com.redplanet.sandboxandroid.ui.MainActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.redplanet.sandboxandroid.ui.SecondActivity"
        android:parentActivityName="com.redplanet.sandboxandroid.ui.MainActivity" >
    </activity>

我的 SecondActivity 类。

public class SecondActivity extends SherlockFragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.countries_list);

        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE);

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
            break;
        }
        return super.onOptionsItemSelected(item);

    }

}

这篇关于回到父活动在清单父活动错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 22:38