|?Android Software Progression
Chapter four. Underneath the Covers: Startup Code and Resources within the MJAndroid Software
Chapter 3 introduced the major software we use with this book to illustrate essential Android concepts. That chapter explained which documents make up the source code, however it didnвЂ™t actually cover any source code while in the software. WeвЂ™ll initiate on the lookout at source code on this chapter. And to help you to definitely get started developing an software without delay, weвЂ™ll begin with the initial task every standalone software has to perform: initialization.
The events covered on this chapter occur around your selecting вЂњRun As Android ApplicationвЂќ from the Eclipse menu and seeing the map that MJAndroid displays at startup. This chapter shows how Android makes it effortless to generate relatively complex apps. In just 80 lines of code and some associated XML resource information, MJAndroid manages to:
Display an interactive map
Track the present location from the Android phone and update the map
Generate a local databases of details and load person preferences into it
Make available a dynamically changing menu
Display consumer interface features this sort of as labels, buttons, and spinners
Run a new Activity to display a supporting screen
The Java code in an Android software interacts tightly with XML resource data files, so weвЂ™ll bounce again and forth around them on this chapter. As we point out repeatedly, XML documents are easier to tweak during advancement and take care of over the life of an software. The style of Android encourages you to definitely specify the appear and behavior within the software while in the resource data files.
Initialization Parameters in AndroidManifest.xml
As Chapter 3 explained, we told Android to launch Microjobs.java since the for starters Activity for MJAndroid. We defined that within the Software tab of your AndroidManifest.xml editor. The to begin with part of your XML code that effects from that choice is demonstrated right here:
This section belonging to the chapter focuses in the XML within this file. The MicroJobs Activity is identified around the manifest within the beginning within the file. This part within the file is normally created in Eclipse if you happen to initial develop the Mission that you just use to write down your software .
Like all proper XML information, line 1 has the standard declaration with the XML version as well as character encoding made use of. Before we get into the Activities that make up the MJAndroid software, we define two or three parameters and declare needed permissions for your whole software:
This is just the package name we gave when we created the software in Eclipse. It is also the default package for all the modules during the software.
This is undoubtedly an integer that should always increment with just about every new version on the software. Every software should include a version code, and it should always be a monotonically increasing integer from version to version. This allows other programs (these as Android Market, installers, and launchers) easily figure out which is the latest version of an software. The filename of your .apk file should include this same version selection, so it is obvious which version it has.
This version identifier is mostly a string, and it is intended to be alot more like the version figures you usually see for purposes. The naming convention is up to you, but generally the idea is to make use of a scheme like m.n.o (for as a lot figures as you intend to use), to identify successive amounts of change to the software. The idea is this is the version identifier that would be displayed to some consumer (either by your software or another software).
There are four of these in MJAndroid, and they declare that the software intends to try functions of Android that require explicit permission from the consumer of your cellular equipment jogging the software. The permission is requested once the software is installed, and from then on Android remembers that the consumer mentioned it was OK (or not) to run this software and obtain the secure amenities. There are a wide range of permissions currently defined in Android, all described inside the Android documentation (search for android.Manifest.permission ). It is possible to also define your possess permissions and use them to restrict other applicationsвЂ™ accessibility to functions with your software, unless the consumer grants another software that permission. The permissions requested right here are:
ACCESS_FINE_LOCATION. which is required to obtain location advice from the GPS sensor.
ACCESS_LOCATION_EXTRA_COMMANDS. The Android documentation doesnвЂ™t tell us which location commands are вЂњextra,вЂќ so weвЂ™ll ask for all of these.
CALL_PHONE. This will allow MJAndroid to request that the Dialer put a cellular phone call on its behalf.
ACCESS_MOCK_LOCATION. so we can get fake location data when weвЂ™re operating underneath the emulator.
INTERNET. so we can retrieve map tiles over an Internet relationship.
This is the filename for a PNG file that has the icon youвЂ™d like to utilize in your software. With this case weвЂ™re telling the Android SDK to look and feel for that icon file with the drawable subdirectory on the res (resources) directory beneath MJAndroid. Android will use this icon in your software around the Android Desktop.
Turning our attention to the definition for your to begin with (and main) Activity, MicroJobs, we for starters define a number of attributes for that Activity:
The name belonging to the Activity. The entire name within the Activity comes with the package name (which in our software is вЂњcom.microjobsinc.mjandroid.MicroJobsвЂќ), but since this file is always made use of from the packageвЂ™s namespace, we do not want to include the leading package names. The Android SDK strips the package name down to вЂњ.MicroJobsвЂќ when it creates this part of AndroidManifest.xml . and even the leading period is optional.
The label that we need to appear within the top belonging to the Android screen in the event the Activity is over the screen. We saw this before in HelloWorld, where we changed the string in strings.xml to match our software.
We then declare an intent filter that tells Android when this Activity should be run. We talked briefly about Intents in Chapter 1. and now we see them in use. As youвЂ™ll recall, when Android encounters an Intent to fulfill, it looks among the readily available Activities and Providers to locate something that can provider the Intent. We established two attributes:
Right now Android is trying to launch this software, so it is hunting for an Activity that declares itself wanting to resolve the MAIN action. Any software which is going to be launched by the Launcher needs to have exactly 1 Activity or Program that makes this assertion.
The Intent resolver in Android takes advantage of this attribute to further qualify the Intent that it is on the lookout for. In this particular case, the qualification is the fact that weвЂ™d like for this Activity to be displayed from the Consumer Menu so the person can select it to start out this software. Specifying the LAUNCHER category accomplishes this. You'll be able to have a perfectly valid software without this attribute-you just wonвЂ™t be able to launch it from the Android person interface. Normally, again, youвЂ™ll have exactly just one LAUNCHER for each software, and it will appear around the same intent filter given that the opening Activity of your software.
The right content on your career. Discover unlimited learning on demand for close to $1/day .
<a href=http://fortheloveof.org.uk/what-could-be-the-future-of-printed-textbooks/>pay for essay in uk</a>