Joke Collection Website - Public benefit messages - How to debug services in Android development
How to debug services in Android development
In Android development, add code to debug services.
introduce
When starting an Android project in debugging mode, set a breakpoint in the service and the debugger will not stop.
solution
In all these cases, it is declared in the code. The method called is:
Android . OS . debug . waitfordebugger();
For example, soft keyboard:
The public class SoftKeyboard extends InputMethodService to realize KeyboardView. OnKeyboardActionListener { @ Override public void onConfigurationChanged(Co configuration new config){ log . d(" soft keyboard "," onConfigurationChanged()"); /* Now let's wait until the debugger attaches */android.os.debug.wait for debugger (); super . onconfigurationchanged(new config); /* Do something useful ... */}
As you can see in the code, the first thing is to call the recorder. When the code runs here, a record will be added to logcat, which is a way to track the code running. If it doesn't need to stop at a breakpoint, you can use it. But usually for more detailed debugging, this is not enough.
The second statement waits for the debugger to be added. After adding this statement, you can add a breakpoint anywhere in this method.
Debugging services is easier when the activity is also part of the application. In this case, you need to start the activity first, and the debugger can also stop at the breakpoint of the service without calling waitForDebugger ().
- Previous article:Can I register successfully without SMS verification?
- Next article:How to choose the two-color ball number
- Related articles
- 03 12-5905095 is the telephone number of Baoding, Hebei? Is it a fraudulent phone call? Thank you.
- Is there any bad omen when you dream that the coal stove is burning vigorously?
- I use my mobile phone to send text messages on my browser. How to delete it now?
- A short message of gratitude from students to their teachers
- Nucleic acid detection 10 hybrid mobile phone.
- Kunshan Epidemic Prevention Center 24-hour telephone number
- What are your best wishes for your 40th and 50th birthdays?
- Model essay on the exchange of speech materials for building a civilized city
- Model essay on commitment letter of civilized internet access
- Aaa authentication of H3C switch failed.