I'm playing around with Android Studio so I created a SettingsActivity using the wizard and I'm faced with the problem that it is not possible to navigate from this settings activity back to the main activity using the "up" arrow in the Actionbar.
The setup of the Actionbar looks like this:
private void setupActionBar() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
// Show the Up button in the action bar.
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
Actionbar is not null btw.
And the parentActitvityName is set in the AndroidManifest:
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.demo.app.MainActivity" />
</activity>
However, a click on the arrow does nothing. Not even onOptionsItemSelected gets triggered.
Seems like this is exactly the same problem Action bar setDisplayHomeAsUpEnabled not working on ICS but navigating back from a detail to an overview activity is working fine in the very same app. Moreover I set MinSDK to 15 and TargetSDK to 23.
override the onOptionsItemSelected
method on your AppCompatPrefernceActivity and make it like this
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
super.onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With