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 8451991
In Process

The Archive Base Latest Questions

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

Basically I’ve got a Menu-class with a start button that starts a new Game

  • 0

Basically I’ve got a Menu-class with a start button that starts a new Game Activity within a Thread.

In the Game class I’ve got instantiated a Count-object (which extends CountDownTimer).

When starting the Game Activity I get an ANR error and I believe it is caused by the timer, since I’ve commented it out and it works perfectly fine. Frankly I do not know how to solve this; I’ve tried different approaches but failed.
Edited code *Logcat at the end*

public class Menu extends Activity {

    Button start, highscores, exit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);
        addListenerOnButton();

    }

    private void addListenerOnButton() {

        start = (Button) findViewById(R.id.start);
        start.setOnClickListener(new OnClickListener() {

            public void onClick(View view) {

                        startActivity(new Intent("net.fb.clauz.GAME"));

                };

        });

        highscores = (Button) findViewById(R.id.highscores);
        highscores.setOnClickListener(new OnClickListener() {

            public void onClick(View view) {

            }
        });

        exit = (Button) findViewById(R.id.exit);
        exit.setOnClickListener(new OnClickListener() {

            public void onClick(View view) {
                finish();
                System.exit(0);
            }
        });

    }
}



public class Game extends Activity {

    Button button;
    TextView score;
    public static TextView timeleft;
    int x = 0;
    public Counter count;
    public static boolean running=true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        count = new Counter(30000, 1000);
        timeleft = (TextView) findViewById(R.id.timeleftTitle);

        gameThread = new Thread(new Runnable() {
            public void run() {
                while (running) {
                    addListenerOnButton();
                    count.start();
                }
            }
        });
        gameThread.start();
    }


    private void addListenerOnButton() {

        button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new OnClickListener() {

            public void onClick(View view) {
                x++;
                score = (TextView) findViewById(R.id.score);
                score.setText(String.valueOf(x));

            }

        });

    }
}



public class Counter extends CountDownTimer{

    public Counter(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onFinish() {
        // TODO Auto-generated method stub
        Game.running = false; // stop the game

        //need to implement action to return to the buttons menu.
    }

    @Override
    public void onTick(long millisUntilFinished) {
        // TODO Auto-generated method stub
        Game.timeleft.setText("Left: " + millisUntilFinished / 1000);
        System.out.println(millisUntilFinished / 1000);
    }

}

Logcat:

08-23 11:00:02.963: W/ActivityManager(885): Activity idle timeout for ActivityRecord{b4ca99d0 net.fb.clauz/.Game}

08-23 11:00:18.343: D/dalvikvm(14424): GC_CONCURRENT freed 3397K, 28% free 9419K/12935K, paused 4ms+4ms

08-23 11:00:21.383: I/InputDispatcher(885): Application is not responding: Window{b4cd2aa8 net.fb.clauz/net.fb.clauz.Game paused=false}.  5005.6ms since event, 5004.9ms since wait started

08-23 11:00:21.383: I/WindowManager(885): Input event dispatching timed out sending to net.fb.clauz/net.fb.clauz.Game

08-23 11:00:21.415: I/Process(885): Sending signal. PID: 14424 SIG: 3

08-23 11:00:21.415: I/dalvikvm(14424): threadid=3: reacting to signal 3

08-23 11:00:21.443: I/dalvikvm(14424): Wrote stack traces to '/data/anr/traces.txt'

08-23 11:00:21.443: I/Process(885): Sending signal. PID: 885 SIG: 3

08-23 11:00:21.443: I/dalvikvm(885): threadid=3: reacting to signal 3

08-23 11:00:21.593: I/dalvikvm(885): Wrote stack traces to '/data/anr/traces.txt'

08-23 11:00:21.593: I/Process(885): Sending signal. PID: 944 SIG: 3

08-23 11:00:21.593: I/dalvikvm(944): threadid=3: reacting to signal 3

08-23 11:00:21.634: I/dalvikvm(944): Wrote stack traces to '/data/anr/traces.txt'

08-23 11:00:21.634: I/Process(885): Sending signal. PID: 976 SIG: 3

08-23 11:00:21.634: I/dalvikvm(976): threadid=3: reacting to signal 3

08-23 11:00:21.673: I/dalvikvm(976): Wrote stack traces to '/data/anr/traces.txt'

08-23 11:00:22.463: D/dalvikvm(885): GC_CONCURRENT freed 472K, 14% free 11275K/13063K, paused 6ms+0ms

08-23 11:00:23.293: D/dalvikvm(885): GC_EXPLICIT freed 326K, 14% free 11328K/13063K, paused 6ms+9ms

08-23 11:00:23.963: E/ActivityManager(885): ANR in net.fb.clauz (net.fb.clauz/.Game)

08-23 11:00:23.963: E/ActivityManager(885): Reason: keyDispatchingTimedOut

08-23 11:00:23.963: E/ActivityManager(885): Load: 1.54 / 0.86 / 0.89

08-23 11:00:23.963: E/ActivityManager(885): CPU usage from 11149ms to 0ms ago:

08-23 11:00:23.963: E/ActivityManager(885):   98% 14424/net.fb.clauz: 96% user + 1.7% kernel / faults: 117 minor

08-23 11:00:23.963: E/ActivityManager(885):   0.6% 778/surfaceflinger: 0.6% user + 0% kernel

08-23 11:00:23.963: E/ActivityManager(885):   0.5% 885/system_server: 0.3% user + 0.1% kernel

08-23 11:00:23.963: E/ActivityManager(885):   0% 944/com.android.systemui: 0% user + 0% kernel / faults: 1 minor

08-23 11:00:23.963: E/ActivityManager(885): 99% TOTAL: 97% user + 1.9% kernel

08-23 11:00:23.963: E/ActivityManager(885): CPU usage from 1917ms to 2519ms later:

08-23 11:00:23.963: E/ActivityManager(885):   92% 14424/net.fb.clauz: 92% user + 0% kernel

08-23 11:00:23.963: E/ActivityManager(885):     46% 14424/net.fb.clauz: 46% user + 0% kernel

08-23 11:00:23.963: E/ActivityManager(885):     46% 14440/Thread-108: 46% user + 0% kernel

08-23 11:00:23.963: E/ActivityManager(885):   8.6% 885/system_server: 3.4% user + 5.1% 
kernel
08-23 11:00:23.963: E/ActivityManager(885):     6.8% 920/InputDispatcher: 3.4% user + 3.4% kernel

08-23 11:00:23.963: E/ActivityManager(885): 100% TOTAL: 95% user + 4.9% kernel

08-23 11:00:24.583: D/dalvikvm(885): GC_CONCURRENT freed 475K, 13% free 11423K/13063K, paused 6ms+15ms

08-23 11:00:38.693: W/ActivityManager(885):   Force finishing activity net.fb.clauz/.Game
  • 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-10T11:23:20+00:00Added an answer on June 10, 2026 at 11:23 am

    Remove Thread.

    start.setOnClickListener(new OnClickListener() {
    
            public void onClick(View view) {
    
    
                        startActivity(new Intent("net.fb.clauz.GAME"));
    
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I've made a form in Cakephp 2.1 with a jQuery button that appends
Basically, I have a button that when you press it, it runs its action
Basically, I have a UIImageView that will loop through 8 PNGs over 0.5 seconds.
Basically from C++ FAQ I learned that: A virtual function allows derived classes to
Basically from a database I am getting data that is formatted like this nameofproject101
Basically I have an iframe loaded that is accessed from the parent whenever it
Basically, I have a main page (parent page) with a link that opens up
Basically this function is meant to store the height value of the element that
basically I have a function that resizes elements accordingly with jquery triggering the function
Basically I have an IFRAME that contains a given page - I want to

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.