Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8461171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:48:23+00:00 2026-06-10T13:48:23+00:00

I have developed a game using andengine I am facing a problem when using

  • 0

I have developed a game using andengine

I am facing a problem when using the power Button. If I press the POWER Button while playing the game the screen turns off and the onPause() is called as expected. But when I press the HOME button or POWER button again to turn on the screen, onResume() method is called and but the lockscreen shows up.

In the onResume() method, I resume the music of the game.

So as a result lockscreen shows up , but the game music plays in the background. I do not want to play the music in the lockscreen. Please help me solving this.Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:48:24+00:00Added an answer on June 10, 2026 at 1:48 pm

    The solution is here: Activity handle when screen unlocked

    By registering a BroadcastReceiver filtering the Intent.ACTION_SCREEN_ON, Intent.ACTION_SCREEN_OFF and Intent.ACTION_SCREEN_PRESENT actions, you will be able to handle these 3 cases:

    • Intent.ACTION_SCREEN_OFF: When the POWER button is pressed and the screen goes black.
    • Intent.ACTION_SCREEN_ON: When the POWER button is pressed again and lockscreen is showed up.
    • Intent.ACTION_SCREEN_PRESENT: When you pass the locksreen and are back in your game.

    However, in my case (using a Galaxy S GT I9000 with Froyo 2.2) these actions are not called when dealing with the HOME button (and I think it’s a general behavior).

    One simple and quick (but maybe not the best) way to handle both HOME and POWER buttons to pause and resume your music could be to keep the onPause and onResume methods and use a simple boolean flag like this:

    private boolean mPowerButton = false;
    
    @Override
    public void onPause() {
        super.onPause();
    
        // Pause your music
        Log.d("Game activity", "Music paused");
    }
    
    @Override
    public void onResume() {
        super.onResume();
    
        if (!this.mPowerButton) {
            // Resume your music
            Log.d("Game activity", "[HOME button] Music resumed inside onResume");
        }
    }
    
    public class receiverScreen extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
    
            if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
                // This is the lockscreen, onResume has been already called at this  
                // step but the mPowerButton boolean prevented the resumption of music
            }
    
            if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
                LevelActivity.this.mPowerButton = true;
            }
    
            if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
                // Resume your music
                Log.d("Game activity", "[POWER button] Music resumed inside ACTION_USER_PRESENT action");
                LevelActivity.this.mPowerButton = false;
            }
        }
    }
    

    Hope it helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a game using andengine with PORTRAIT_FIXED ScreenOrientation . This is a
I'm using AndEngine/Box2d to develop a game. I have a ball that bounces around
I have developed a little game using XNA 4.0 and C# (new Project->Windows Game
I have a game site developed using flash and php. The php code contains
i am using box2d to developed iphone game.But i have not a lot of
I have developed a game using HTML5 and Javascript/JQuery. This game is a Tile
I have developed a ios game with 20 levels. I have menu at starting
I have developed an AJAX based game where there is a bug caused (very
I have developed tower of hanoi game in java script. Now, I want to
I have developed a small administration page for game servers which you can add/remove/edit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.