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

  • SEARCH
  • Home
  • 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 8364883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:32:10+00:00 2026-06-09T12:32:10+00:00

I’m writing a 2D engine on android. I can receive touch input and update

  • 0

I’m writing a 2D engine on android. I can receive touch input and update my scene according to touch events but there is a problem. When I restart the application after losing focus (clicking home screen button, receiving a call etc..) I can no longer receive touch input, screen still displays the content but it stays frozen.
Is there a way to fix this issue?

Here is the code :

import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.app.Activity;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.WindowManager;
import android.media.AudioManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.util.DisplayMetrics;

public class SolarFighter extends Activity implements OnTouchListener
{
Game            game;
GraphicsManager graphicsMan;
SoundManager    soundMan;
ErrorManager    errorMan;
FrameSetManager frameSetMan;
SpriteManager   spriteMan;
InputManager    inputMan;
WakeLock        wakeLock;

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    //
    //Go full screen
    //

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);

    PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
    wakeLock                  = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Lock");


    //
    // Get system information
    //

    DisplayMetrics displaymetrics = new DisplayMetrics();

    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);

    int height = displaymetrics.heightPixels;
    int width  = displaymetrics.widthPixels;

    //
    // Create Graphics Manager and load spriteSheets load fonts
    //

    graphicsMan = new GraphicsManager(width,height,this);
    graphicsMan.addFont(0, "fonts/font.ttf", this);      

    //
    // Create Sound Manager and add sounds
    //

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    //
    // Create Input Manager
    //
    inputMan = new InputManager();

    //
    // Create Frame Set Manager and add frame sets
    //

    //
    // Create Sprite Manager and add sprites
    //

    //
    // Create Entity Manager and add entities
    //

    //
    // Create Game
    //

    game = new Game(this);

    game.setOnTouchListener(this);  
    setContentView(game);

}

public void onResume() 
{
    super.onResume();

    wakeLock.acquire();

    game.resume();
}

public void onPause()
{
    super.onPause();

    wakeLock.release();

    game.pause();
}

public boolean onTouch(View v, MotionEvent event) 
{
    switch (event.getAction())
    {
        case MotionEvent.ACTION_DOWN:
            inputMan.setTouchState(InputManager.TOUCH_DOWN);
            inputMan.setLastX((int)(event.getX()));
            inputMan.setLastY((int)(event.getY()));
        break;

        case MotionEvent.ACTION_MOVE:
            inputMan.setTouchState(InputManager.TOUCH_MOVE);    
            inputMan.setCurrentX((int)(event.getX()));
            inputMan.setCurrentY((int)(event.getY()));
            inputMan.setRelativeX(inputMan.getCurrentX() - inputMan.getLastX());
            inputMan.setRelativeY(inputMan.getCurrentY() - inputMan.getLastY());    
            inputMan.setLastX(inputMan.getCurrentX());
            inputMan.setLastY(inputMan.getCurrentY());
        break;

        case MotionEvent.ACTION_CANCEL:
            inputMan.setTouchState(InputManager.TOUCH_UP);
        break;

        case MotionEvent.ACTION_UP:
            inputMan.setTouchState(InputManager.TOUCH_UP);
        break;
    }
    return true;
}

class Game extends SurfaceView implements Runnable
{
    private Thread            renderThread = null;
    private SurfaceHolder     holder;
    private volatile boolean  running = false;  

    private int  x  = 0,y = 0;
    private int  xx = 250;
    private int  xy = 400;

    public Game(Context context)
    {
        super(context);

        holder = getHolder();   
    }

    public void resume() 
    {
        running      = true;
        renderThread = new Thread(this);

        renderThread.start();
    }

    public void run() 
    {
        while(running) 
        {
            if(!holder.getSurface().isValid())
            {
                continue;
            }

            //
            // Update Scene
            //


            //
            // Render scene
            //

            graphicsMan.beginScene(holder);
            graphicsMan.clearScene();   
            x = inputMan.getRelativeX();
            y = inputMan.getRelativeY();
            if(inputMan.getTouchState() == InputManager.TOUCH_MOVE)
            {
                xx += x;
                xy += y;
            }
            graphicsMan.drawText(0, "X", Color.RED,40,xx, xy);
            graphicsMan.endScene(holder);
        }
    }

    public void pause() 
    {
        running = false;

        while(true) 
        {
            try 
            {
                renderThread.join();
            } 
            catch (InterruptedException e)
            {
                // retry
            }
        }
    }
}
}
  • 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-09T12:32:12+00:00Added an answer on June 9, 2026 at 12:32 pm

    I got rid of the entire while statement of Game’s pause method and the problem is solved.

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from

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.