Android Programming Tutorials

(Romina) #1
Your Friends Seem Remote

Step #2: Create a Fresh Project.........................................................


First, we should create a separate project for the PostMonitor, to simulate it


being some third-party component and to force it to run in a separate


process as a separate user.


So, via android create project or Eclipse, create a TMonitor project peer of


Patchy, using the package apt.tutorial.three (so TMonitor and Patchy can


both be on the emulator at the same time).


Step #3: Move the Service to the New Project.................................


Now, let us move the PostMonitor code from Patchy into the new TMonitor


project.


First, move Patchy/src/apt/tutorial/two/PostMonitor.java to


TMonitor/src/apt/tutorial/three, replacing the automatically-generated


PostMonitor.java. Also, go in and fix up the package statement, reflecting


that the new PostMonitor is in apt.tutorial.three.


Then, since both Patchy and PostMonitor need the JTwitter JAR, copy that jar


from Patchy/libs/ to TMonitor/libs/.


Next, modify TMonitor/AndroidManifest.xml to get rid of the


element (since TMonitor has no activity) and replace it with the


element from Patchy/AndroidManifest.xml. While you have


Patchy/AndroidManifest.xml open, get rid of that element after you


have put it in the TMonitor/AndroidManifest.xml file.


Finally, since we removed the PostMonitor class from Patchy, we need to get


rid of the compiled edition of that class. If you are using Eclipse, force a


rebuild of your project; otherwise, get rid of Patchy/bin/, so on the next


recompile, it will not have any of the old code lying around.


204
Free download pdf