-2

I have a main activity in my app. This activity creates two other activities (at different times). One is a settings activity and the other is a custom activity.

Now my problem is when i am in the settings activity and i press the back button, it returns to the main activity. Great just like it should. But now when i am in my custom activity and i press the back button the entire app closes?? It does not return to the main activity like it should.

I am not sure why this is, as the way i instantiate the two classes is the same and the manifest file is the same for both activities.

Code to call the activities:

Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);

and

Intent intent = new Intent(this, PacketActivity.class);
startActivity(intent);

Manifest file:

<activity
    android:name="com.example.tcptester.SettingsActivity"
    android:label="@string/title_activity_settings" >
</activity>
<activity
    android:name="com.example.tcptester.PacketActivity"
    android:label="@string/title_activity_packet">
</activity>

Why could this be so?

j0k
  • 22,600
  • 28
  • 79
  • 90
Zapnologica
  • 22,170
  • 44
  • 158
  • 253
  • 2
    -1 because you gave different code in question, and different code in answer Assuming there is no connection between this two cases. And that's why we wouldn't be able help you anyway. – deadfish Mar 14 '13 at 09:00

1 Answers1

0

I found the problem,

Thought i would post the answer for any one else who maybe have the same problem,

The problem was in my switch statement: I left out a return true.

    switch (item.getItemId()) {
    case R.id.menu_packet: {
        Intent intent = new Intent(this, PacketActivity.class);
        startActivity(intent);
        /*-->>>>> i did not have this here:*/ return true;
    }
    case R.id.menu_settings: {
        Log.i("Menu Item Clicked", "Settings");
        Intent intent = new Intent(this, SettingsActivity.class);
        startActivity(intent);
        return true;
    }       
    default: {
        return super.onOptionsItemSelected(item);
    }
    }
Zapnologica
  • 22,170
  • 44
  • 158
  • 253