How to debug a Service?
Introduction
When you start a project with a service in it in debug mode, and you placed a breakpoint in a method of the service, the debugger will not stop.
The solution that works in almost all situation is to wait declaratively in the code for the debugger to attach. To do this, you have to make a call to:
- android.os.Debug.waitForDebugger();
The breakpoint can be inserted at any line after this call.
As a complete example, the SoftKeyboard tutorial is enhanced with the call above:
- public class SoftKeyboard extends InputMethodService
- implements KeyboardView.OnKeyboardActionListener {
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- Log.d("SoftKeyboard", "onConfigurationChanged()");
- /* now let's wait until the debugger attaches */
- android.os.Debug.waitForDebugger();
- super.onConfigurationChanged(newConfig);
- /* do something useful... */
- }
As you can see in the code, the first call in the method is a call to the logger, with which we can see in the Log output when our method was called. This can be an other way of tracking our method calls, without the need to stop at a breakpoint. But usually this is not enough for detailed debugging.
Then the second statement waits for the debugger to attach, as it is also noted in the comment. After this line the breakpoint can be inserted anywhere in the method.
Debugging a Service in case an Activity is also part of the application is even easier. In that case the activity has to be started first, then the debugger is able to stop at the breakpoint in the service as well, without the need of an explicit waitForDebugger() call.





Comments
I see some other commenters
I see some other commenters giving you crap for your writing style. I think it’s bold and on the psychological level it’s a title that calls attention to it. Usually I don’t read many blogs but this one caught my eye just by the title. That’s a digi sport live good example of writing at it’s best. Some people say the vulgarity is unnecessary but it’s probably biletul zilei the reason they read this post as well, so mission accomplished. Good job...
Great Work !!!
I have been searching for this code for a long time. This is very useful and important to me. Great work done !!!
memory foam
A server, which runs as a
A server, which runs as a background process on your development machine. The server manages communication between the client and the adb daemon running on an emulator or device.
http://realmakemoneyonline.com
In case you defined your
In case you defined your service to use a remote process, you can remove the "remote" property in the manifest file, and develop+debug it like that. In case your code is mature enough, you can switch to use a remote process again.
You can invoke a client from
You can invoke a client from a shell by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients.
Forex Reviews
You define your service to
You define your service to use a remote process, you can remove the "remote" property in the manifest file, and develop+debug it like that.
affiliate dot com
"Debug" is vital for every
"Debug" is vital for every software. When it is along with the application then the problem is very simple.
???? ???? | ??????? ?????? | ???? ???
CRM system
This is a excellent posting, I located your website browsing aol for a related topic and arrived to this. I couldn't get to much other details on this piece, so it was great to find this one. I will probably end up being back to check out some other posts that you have another time.... CRM system
Yea it works i tried it
I have been able to get it working for local processes. Thanks alot for your help. i have ot admit i was struggling for a fair bit
Hugh Jackman Workout
Starcraft 2 Guide
Kidney Diet
It appears that the only way
It appears that the only way is to remove android:process=":remote" temporarily in the manifest. Free directory
Looking ahead more. Hope this
Looking ahead more. Hope this will useful for everyone. Thanks
shopping cart
This can be an other way of
This can be an other way of tracking our method calls, without the need to stop at a breakpoint. But usually this is not enough for detailed debugging.
mattress ireland
Took me time to apprehend all
Took me time to apprehend all the comments, but I absolutely enjoyed the article. It accepted to be Very admiring to me and I am abiding to all the commenter’s here! It’s consistently nice back you can not alone be knowledgeable, but additionally entertained! I’m abiding you had fun autograph this article. [ triathlon bike ] [ triathlon wetsuit ]
Great tutorial
Please make some more tutorials like this! Very helpful.
Droid 2 Case
I think Ogg is much easier to
I think Ogg is much easier to user, but when Google Sync works right for me, it’s great.
Kenilworth Toyota
"Debug" is vital for every
"Debug" is vital for every software. When it is along with the application then the problem is very simple.
Buy Sheet Music Online
Debugging is very important.
Debugging is very important. If the debugger is a part of the application the it is very easy.
brisbane orthotics
Excellent information. I've
Excellent information. I've been trying to figure out how to debug my Droid for some time now.
Droid 2
LG HDTV
Its a very good idea, and
Its a very good idea, and some of the comments have added onto the utility of the method of service debugging. Very helpful. Thanks.
Home Security Companies Searching for Alarm Companies? - Call Walker Home Security
Tutorial helped a lot and you
Tutorial helped a lot and you really make it clear and easy to understand. Thanks for sharing.
tubside bath seat
mp3 dinle
mp3 dinle
In Visual Studio.Net, you
In Visual Studio.Net, you attach to the process (Debug|Processes... menu), and then you can debug as usual. Hope it will work.
Pariuri sportive, Bonusuri pariuri, Biletul zilei
You can invoke a client from
You can invoke a client from a shell by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients.
Reusable Ice packs
I have used both Ogg Sync and
I have used both Ogg Sync and Google Sync for my Android. I can’t seem to decide on one over the other. Sometimes I think Ogg is much easier to user, but when Google Sync works right for me, it’s great.
Kodak Digital Frame
Gadgets and Gizmos
Debugging a Service in case
Debugging a Service in case an Activity is also part of the application is even easier. In that case the activity has to be started first, then the debugger is able to stop at the breakpoint in the service as well, without the need of an explicit waitForDebugger() call.
oracle trader
A client, which runs on your
A client, which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients.
Gold Grills
Great Article
Great tutorial, you really make it clear and easy to understand. What I really would like to grumble about is IE6 (and the other 2 versions of IE, although they're a bit better)
Microsoft should really launch a concerted effort to get people to update their browsers to IE8, because more and more web designers and web design firms are not making IE6 compliance a priority at all.
In an ideal world everybody will start using FireFox, while there is better and better incarnations of Chrome with every update, leaving people spoilt for choice of fast and secure (and free!) web browsers.
If only people will listen when you recommend a new browser though. Change is something which lots of people don't want to deal with. They're comfortable using IE and don't want to have to learn how to work new things...sad really.
müzik indir
Took me time to read all the
Took me time to read all the comments, but I really enjoyed the article. It proved to be Very supportive to me and I am sure to all the commenter’s here! It’s always nice when you can not only be knowledgeable, but also entertained! I’m sure you had fun writing this article.
translation directory
translation agency
Wow
I can read n follow this tutorial, but I can do it without some example (tutorial)
Indonesia Furniture Handicraft Wholesale Marketplace - Blogger Indonesia Dukung Internet Aman, Sehat & Manfaat - Belajar Ngeblog - Seo Support - Marware Iphone & Ipad - Read Manga Online
bitkisel tedavi
bitkisel tedavi yöntemlerini bulabilece?iniz ve bitkisel tedavi
'de kullan?lan ?ifal? bitkilerle ilgili ayr?nt?l? bilgilere ula?abilece?iniz bir sa?l?k sitesi
sikis videosu
Ate?li, s?cak ve fantezi konulu sikis videosu
izleyebilece?iniz bir erotik video sitesi.
I have used both Ogg Sync and
I have used both Ogg Sync and Google Sync for my Android. I can’t seem to decide on one over the other. Sometimes I think Ogg is much easier to user, but when Google Sync works right for me, it’s great.bmw x1
i dont know debug
I do not quite understand about the problem of debugging, if I may know what it is about debugging?
Financil and business
interesting
I am not into hardcore coding, but did understand the logic of the post. Its a very good idea, and some of the comments have added onto the utility of the method of service debugging. Nice.
bling ice
I have used both Ogg Sync and
I have used both Ogg Sync and Google Sync for my Android. I can’t seem to decide on one over the other. Sometimes I think Ogg is much easier to use.Adult Blu-ray
This a very useful and simple
This a very useful and simple solution on how to debug a service. I had the same problem with the easy saver service and your method of debugging worked like a charm, thank you!
Thank you, just what ive been
Thank you, just what ive been looking for... seems much easier than i thought so will def. go ahead and try it for myself. Best, - jonathan budd mastermind
Thanks!
Thanks! It seems to be very easy. Here I've found some more interesting information: http://www.videorolls.com/watch/Debug-Tutorial-1
debug mode
There are 2 main ways to do this. I prefer to build business classes that do
the actual work of the service related to graphic designer. I can then test them in a Windows
executable, and once debugged, plug them into a service. The other way is a
bit more difficult.
You create your Service. You install it and start it. In Visual Studio.Net,
you attach to the process (Debug|Processes... menu), and then you can debug
as usual.
Migration on a Windows mobile
Migration on a Windows mobile is about as simple and effective as those new USB tethering features or, in other words, not so much. I have used both Ogg Sync and Google Sync for my Android. I can’t seem to decide on one over the other. Sometimes I think Ogg is much easier to user, but when Google Sync works right for me, it’s great.
Amazing tut
Never knew this small line of codes can debug. Thanks for the tutorial.
Matthew Proman
Maybe malaysia is the best
Maybe malaysia is the best destination to retire but for my point of view the best place for a holiday is australia because the best hotels are the Hotels in Brisbane and the people are just great .
Very helpful debugging
Very helpful debugging tutorial!Thanks!
Sorin M
http://directory2009.com/
Very helpful debugging
Very helpful debugging tutorial!
-wc
Did you try what they
Did you try what they suggested below? This is also the same problem I have, the reason why I arrived in this site.
Hotels In Jerusalem
Juicy Couture in All Categories
Fantastic post. Your post was that great, keep it up.
juicy couture
Juicy Couture Handbags
Doesn't seem to work for
Doesn't seem to work for remote services with Activities in the same project.
waitForDebugger() caused the emulator to wait until infinity ended ;), and breakpoints just were ignored.
Seems the only way is to remove android:process=":remote" temporarily in the manifest. Or did anybody find a better solution?
Works for local processes
The above described solution does work for local processes.
In case you defined your service to use a remote process, you can remove the "remote" property in the manifest file, and develop+debug it like that. In case your code is mature enough, you can switch to use a remote process again.