Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging error on Android emulator: black screen

I found a problem while I was trying to debug the next code:

package course.examples.theanswer;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class TheAnswer extends Activity {

public static final int[] answers = { 42, -10, 0, 100, 1000 };
public static final int answer = 42;

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

      setContentView(R.layout.answer_layout);

      TextView answerView = (TextView) findViewById(R.id.answer_view);

          int val = findAnswer();
      String output = (val == answer) ? "42" : "We may never know";
      answerView.setText("The answer to life, the universe and everything is:\n\n"
                    + output);
}

private int findAnswer() {
    for (int val : answers) {
        if (val == answer)
            return val;
    }
    return -1;
}

}

I have inserted a break-point in the line "int val = findAnswer();", that is to say, before the app executes the message("The answer to life..."). So, the emulator shows the white screen with the title, it's right, but when it passes about 10 seconds the screen turns black... and the logCat shows the next message:

01-23 05:57:29.995: I/System.out(2009): waiting for debugger to settle...
01-23 05:57:30.205: I/System.out(2009): debugger has settled (1309)
01-23 05:57:30.845: D/dalvikvm(2009): threadid=1: still suspended after undo (sc=1 dc=1)
01-23 05:57:37.825: W/ActivityManager(1254): Launch timeout has expired, giving up wake lock!
01-23 05:57:37.835: E/WindowManager(1254): Starting window AppWindowToken{b33e2a00 token=Token{b3344b58 ActivityRecord{b317b130 u0 course.examples.theanswer/.TheAnswer t10}}} timed out

Tthe final message is when the screen turns black. I can't post images but the emulator only shows: hour, network and battery. Also, if I pressed "resumen" button, the app fihishes fine. However, I think that is not the idea. It should stop with the white screen to keep debugging...(I think, but I'm not sure). Is it normal?

Can anyone help me please?

Thank you

like image 380
adrianoubk Avatar asked Jan 23 '14 11:01

adrianoubk


People also ask

How do I fix my Android Emulator?

If the emulator fails to launch due to the error vulkan-1. dll cannot be found , you probably need to update the emulator. To update the emulator in Android Studio, go to Tools > SDK Manager and install the latest stable version of Android platform.


1 Answers

The explanation is simple, but I don't know how to change this behavior:

When an Android app is running the main thread should process all incoming messages (from GUI and other internal messages). It is strictly forbidden to use the main thread for long lasting operations because in that time the thread is blocked and can not process messages.

When you start an app Android gives 10 seconds to the app to start-up. Afterwards it expects that the app is up for processing messages.

Now to your problem:

You have set a break-point in onCreate(..) a method that is called by the main thread - a thread that should not be blocked. Setting a break-point is nothing else that interrupting/blocking the thread until you press resume. Hence after 10 seconds the Android system (which is not affected by your debugger) expects the app to be finished with starting-up. But the main thread is still trapped by the break-point! Therefore Android thinks that the app failed to start-up and stops certain part responsible for the GUI.

The only solution I see would be to disable this "Launch timeout" - however I don't have a clue if or how this is possible.

like image 152
Robert Avatar answered Nov 09 '22 20:11

Robert