6

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>

This is the error log:

   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?

codeMagic
  • 44,549
  • 13
  • 77
  • 93
Brax
  • 61
  • 1
  • 2
  • Can you post your code around line 41 of your `GeneralAndSecurity` class? The log says it's crashing there. Also check out [this post's](http://stackoverflow.com/questions/12276027/how-can-i-return-to-a-parent-activity-correctly) question/answers and see if they help. – Mxyk Mar 20 '13 at 22:21

3 Answers3

2

The same worked for me without meta-data

Here is my example.

    <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>

My SecondActivity class.

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);

    }

}
Maksim Dmitriev
  • 5,985
  • 12
  • 73
  • 138
  • 3
    This may work for you as android:parentActivityName was introduced in api 16. To support api's levels 4 - 16, you need to declare a parent activity with a and "android.support.PARENT_ACTIVITY" as above. – speedynomads Oct 25 '13 at 14:41
2

I've had the same problem but it was simply a typo in the package name. Did you double-check package and class name?

winne2
  • 2,188
  • 2
  • 17
  • 13
0

Try in your manifest to add this on your parent Activity:

android:allowBackup="true"

Example:

<activity
    android:name=".View.MainActivity"
    android:allowBackup="true">
</activity>

<activity 
    android:name=".View.ChildActivity"
    android:parentActivityName=".View.ChildActivity">
    <meta-data
         android:name="android.support.PARENT_ACTIVITY"
         android:value=".View.MainActivity" />
</activity>

And in your ChildActivity:

public class ChildActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_child);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

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