I'm currently trying to enable up navigation in my Android app. To do so, I followed the tutorial and implemented the necessary code into my activity:
SettingsActivity.java
package de.ntraum.arcon;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.view.MenuItem;
public class SettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setHomeButtonEnabled(true);
addPreferencesFromResource(R.xml.settings);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
startActivity(new Intent(SettingsActivity.this, MainActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
If relevant, here's the AndroidManifest.xml
and styles.xml
:
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.ntraum.arcon"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Light" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
android:exported="false"
android:label="@string/title_activity_settings" >
<intent-filter>
<category android:name="android.intent.category.PREFERENCE" />
</intent-filter>
</activity>
</application>
</manifest>
styles.xml
<resources>
<style name="Light" parent="android:Theme.Holo.Light.DarkActionBar" />
<style name="Dark" parent="android:Theme.Holo" />
</resources>
Issue
The thing is, when accessing the activity, the up indicator in the action bar is missing. Nevertheless, the navigation is actually working (it takes me back to the MainActivity.class
), it's just the small indicator that does not show up correctly.
I've tested it on my own device and in the emulator so far.