Return to parent activity with parent activity error in manifest

This is the manifest code associated with the object:

<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 the back button returns me an error message?

+6
source share
3 answers

The same thing was 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); } } 
+2
source

I had the same problem, but it was just a typo in the package name. Have you double checked the package name and class?

+2
source

Try in the manifest to add this to your parent mode.

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); } } 
0
source

All Articles