Note that there are some explanatory texts on larger screens.

plurals
  1. POANR error while starting new Activity
    primarykey
    data
    text
    <p>Basically I've got a Menu-class with a start button that starts a new Game Activity within a Thread. </p> <p>In the Game class I've got instantiated a Count-object (which extends CountDownTimer). </p> <p>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. <strong>Edited code</strong> *<em>Logcat at the end</em>*</p> <pre><code>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); } } </code></pre> <p>Logcat:</p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload