Most people that are developing Android applications using Eclipse will probably use theEclipse ADT plugin. The plugin offers a lot of functionality, including
In this short article, we'll be discussing the debugging of remote android processes (the processes defined in your manifest using the android:remote attribute). |
Each component in the Android stack (Activity, Service, Receiver and Provider) is defined in the manifest file of your application. For example, an Activity is usually defined like this :
1 |
2 |
3 |
4 |
5 |
6 |
7 |
The activity here will run in the main thread of the application process. If you put a breakpoint in your onCreate method, you'll see this in the debugger :
A few things we should note here :
- We see the debugger is connected to the DalvikVM via localhost:8627.
- Our Activity is created in the main application thread (identified by <3> main).
If we go to the DDMS perspective, we see the following :
As you can see, we see our emulator (identified by emulator-5554) hosting a number of processes including the process that is currently running our application (identified by our application package com.ecs.android.sample.remoteprocess). Here, you also see the debug port that allows us to attach a debugger (port 8627). The green bug next to our application process indicates that a debugger is attached.
From this screen, it is possible to start debugging other applications (represented by different processes), providing you have a source project in your workspace. In the example here, I have an android project that hosts the application identified by the com.ecs.latify package, so I can select com.ecs.latify, and hit the green bug to start debugging the selected process. As soon as you do this, 2 things will happen :
A green bug will be put alongside the process.
Your Eclipse debug perspective will now have a second Android application ready to be debugged.
We'll now add a button to our application that launches a second activity, but this time, we'll configure the activity to run in a different process using the android:process attribute in the manifest.
1 |
2 |
3 |
4 |
We'll put a breakpoint in the onCreate() method of the RemoteActivity and launch the application in debugmode. You'll notice that the debugger will not be suspended when the second activity is shown. The reason being that the second activity runs in a totaly different process. If we switch back to the DDMS perspective, we'll see our RemoteActivityProcess. Notice how it runs as a seperate process, using a seperate port (8631).
In order to hook up a debugger, one would expect that selected the process, and clicking on the green bug would be sufficient (like we did in the previous section). Unfortunately, due to reasons unclear to me, Eclipse shows the following dialog :
The only way to debug this process is by creating a remote java application in eclipse, pointing to the port (8631) as defined the DDMS process overview.
Only then will we able to suspend the debugger on the breakpoint that was put on the activity configured to run in a remote process.
0 件のコメント:
コメントを投稿