Game doesn't Quit properly

Posted by W.K.S on Stack Overflow See other posts from Stack Overflow or by W.K.S
Published on 2012-03-29T11:27:54Z Indexed on 2012/03/29 11:28 UTC
Read the original article Hit count: 171

Filed under:
|

I have an app that so far consists of two Activities:

  • The Main Menu Activity.

  • The Game Activity

The Main Menu Activity contains a button that starts the Game Activity with the following code:

public void onClick(View clickedButton)
    {
        switch(clickedButton.getId())
        {
        case R.id.buttonPlay:
            Intent i = new Intent("apple.banana.BouncingBallActivity");
            startActivity(i);
            break;
    }

When the user is done with the Game Activity, he presses the back button. This calls the onPause() method first, which pauses the animation thread of the game. It then calls the onStop() which calls finish() on the activity altogether. The user is returned to the Main Menu activity. The code is outlined below:

public class BouncingBallActivity extends Activity{


    private BouncingBallView bouncingBallView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bouncingBallView = new BouncingBallView(this);
        bouncingBallView.resume();
        setContentView(bouncingBallView);
    }

    @Override
    protected void onPause()
    {
        super.onPause();
        bouncingBallView.pause();
    }

    @Override
    protected void onResume()
    {
        super.onResume();
        bouncingBallView.resume();
    }

    @Override
    protected void onStop()
    {
        super.onStop();
        this.finish();
    }
}

The problem is that this only works if I launch the application from Eclipse. When I click on the app icon, the game starts from the Game Activity. The main menu activity does not appear.

I am not clear about why this happens. It could be something to do with the manifest. I've pasted the relevant portions below:

<application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".BouncingBallActivity"
            android:label="@string/app_name"
            android:screenOrientation="landscape" >
            <intent-filter>
                <action android:name="apple.banana.BouncingBallActivity" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainMenu"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

I'd really appreciate any help with this. Thanks.

© Stack Overflow or respective owner

Related posts about android

Related posts about android-lifecycle