I have implemented a Back-Button for all Activities except the MainActivity
.
My Problem is that i have a Back-Button in that MainActivity
too.
Hopefully I've imported the right class:
import android.support.v4.app.NavUtils;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getActionBar().setDisplayHomeAsUpEnabled(true);
[...]
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.ueber:
startActivity(new Intent(this, menu_main_Activity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
AndroidManifest:
<application
android:allowBackup="true"
android:icon="@mipmap/levox"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".ListViewActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ListTasksActivity"
android:label="@string/projekte"
android:parentActivityName=".ListViewActivity">
</activity>
<activity android:name=".ListSingleTaskActivity"
android:label="@string/tasks"
android:parentActivityName=".ListTasksActivity">
</activity>
<activity android:name=".menu_main_Activity"/>
</application>
Why i get a Back-Button at MainActivity
too?
The first question is: What do you mean by "Back-Button"?
Do you mean the button which is shown by a little arrow directing to the left, just next to the App-Icon on the top left of your application? That button is called "Up-Button" in the Android-universe. This one is shown in your MainActivity because of this line in your code:
in the method
So you should take away this line. To disable not just the appearance of the button but also the functionality of it, you have to take a look at this part of the code:
Here, you have to remove the part
EDIT: But if you actually want to have the "Up-Button" visible inside an Activity, you
have to set the code
in the onCreate()-method of that Activity!
provide a parent-Activity in your Manifest.xml (what you're doing already), for example:
and put the part
into the Activity which shall have got the "Up-Button".
If you mean anything else, please specify your question and provide more code :)
Some useful links: