There are a activities in my application. Lets call them activities 1,2,3. All of them child to MainActivity. In my application I define for each child activity:

        android:parentActivityName="MainActivity" >
            android:value="MainActivity" />

In onOptionsItemSelected it handled:

    else if(item.getItemId() == R.id.set_general_settings){
        Intent intent = new Intent(this, GeneralSettingsActivity.class); 

However if I navigate for example from main->1->2->3 and then press up button it return me 3->2->1-> main. It does not return me to 3->main. What can be the reason?

Это было полезно?


To handle the hardware back button, you can use this code (found on How to handle back button in activity)

public void onBackPressed() {//for api level 5
    // your code.

public boolean onKeyDown(int keyCode, KeyEvent event) {//higher than api 5
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // your code
        return true;

    return super.onKeyDown(keyCode, event);

Use the first one if you have your minimum API set at level 5 or lower (as far as I can tell that should work)

Now, we need to navigate up. So, where the your code comment is, you should be able to write:


and have it navigate up properly.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top