SyntaxHighlighter

Wednesday, September 22, 2010

Android Programming Jumpstart - 1

image These series of labs are intended to give interested parties a quick ramp up on programming for the Android environment.  I will converting these to a wiki page in the future so that others can add to them.
I will not be spending much time regarding setting up a tool of choice.  I normally use Motodev or Eclipse.  The setup for these is already well documented online and the Motodev installer takes care of a lot for you.  First lets review some basic terminology that will be used a lot.

  • Activities
    • User interface building block,
    • Similar to PC window or dialog
    • Short lived, can be shut down anytime
  • Content Provider
    • Provide abstraction of data stored on device that is accessible by multiple apps
    • Maintain control over how your data is access
    • Short lived, can be shut down anytime
  • Services
    • Designed to keep running independent of an activity
    • Background processing
    • example: music player
  • Intents
    • System messages, notifying apps of events
    • Can respond to and create your own
  • View
    • Building block for UIs
    • Base class for widgets
  • ViewGroup
    • Subclass of View
    • Base class for layouts, containers for Views or ViewGroups
What’s built into the environment
  • Storage
    • Package data files for things that don’t change like icons and help files
    • Get space on device or SD card for databases or files storing user entered data
  • Network
    • Most devices internet ready
    • Can access Java sockets
    • WebKit Web Browser widget
  • Multimedia
    • Play back and record audio and video
  • GPS
    • Most devices have GPS
  • Phone
    • Apps can start phone calls, send and receive text messages
Project Folder Structure
  • AndroidManifest.xml
    • key element
    • Lists all activities, services, permissions, API level
    • Used by Android Market to filter what apps are offered. So min Android 2.0 apps won’t be offered to someone running Android 1.5
  • default.properties – generated file – do not touch
  • build.xml – not needed if using IDE, Ant script, generated
  • src/ - java source code
  • gen/
    • Android build tools use this for source code they generate
    • generated – do not touch
    • R.java will be in here and is used to reference items
  • –es/ - icons, layouts
  • bin/ - compiled output
  • assets/ - files you want packaged with your app
  • libs/ - use this folder to hold third party JARs
  • tests/ - holds separate project for testing yours – I haven’t used this yet
  • APK file – the zip archive that is essentially the android executable
AndroidManifest.xml
  • uses-permission element – indicates what permissions your app needs
  • permissions elements – declares the permissions that Activities and Services require other apps to have in order to interact with your app
  • instrumentation elements – indicates the code that is invoked on key system events
  • uses-library elements – attach to optional Android components
  • uses-sdk element
  • indicate the version of Android SDK the app was built for
  • Set minSdkVersion for Android Market
  • application element – define your app
  • activity elements
  • android.name – class implementing the activity
  • android.label – display name for the activity
  • intent-filter – under what conditions the activity will be displayed
  • receiver – non-activities that should be triggered under certain conditions
  • provider – components that supply data to activities
  • services – longer running code that can operate independently
Android Emulators
  • Setup via AVD Manager
  • Meant to simulate real Android devices
  • Must specify target
  • What type of device will the AVD pretend to be
  • Can’t edit after creating
Android SDK and AVD Manager
image
  • Can be launched from within Motodev or via command line
  • Available Packages - Install and update Android SDK components
  • Select the components to install
  • Updates will also be listed here
  • Can add additional sites to look for components
  • Virtual Devices - Create and edit Android Virtual Devices (AVDs) that provide the emulator for testing apps
  • Each AVD behaves as a totally distinct device, so installing your app on one AVD does not affect any other AVDs that you have created.
  • More detailed instructions are available on the Android developer site
  • http://developer.android.com/sdk/adding-components.html
  • Creating the AVD
    • Google info
    • Name the AVD
    • I like to include the version
    • Set the target level
    • Can leave the rest as is
    • After you create the AVD you will see it listed in the devices tab
    • Start it!
image

image 


Creating a new project requires: 
  •   Project name
  •   Contents location
  •   Target
  •   App Name
  •   Package Name – must have at least two identifiers
  •   Activity Name – if creating
  •   Min SDK Version - optional













image

What you can find in your project Folder Structure
  • src/ - java source code
  • gen/
  • Android build tools use this for source code they generate
  • generated – do not touch
  • R.java will be in here and is used to reference items
  • assets/ - files you want packaged with your app
  • res/ - icons, layouts
  • AndroidManifest.xml
  • key element
  • Lists all activities, services, permissions, API level
  • Used by Android Market to filter what apps are offered. So min Android 2.0 apps won’t be offered to someone running Android 1.5
  • default.properties – generated file – do not touch
  • build.xml – not needed if using IDE, Ant script, generated
  • bin/ - compiled output
  • libs/ - use this folder to hold third party JARs
  • tests/ - holds separate project for testing yours – I haven’t used this yet
  • APK file – the zip archive that is essentially the android executable
AndroidManifest.xml
  • Every application must have an AndroidManifest.xml file in its root directory. The manifest presents information about the application to the Android system, information the system must have before it can run any of the application's code
  • uses-permission element – indicates what permissions your app needs
  • permissions elements – declares the permissions that Activities and Services require other apps to have in order to interact with your app
  • instrumentation elements – indicates the code that is invoked on key system events
  • uses-library elements – attach to optional Android components
  • uses-sdk element
  • indicate the version of Android SDK the app was built for
  • Set minSdkVersion for Android Market
  • application element – define your app
  • activity elements
  • android.name – class implementing the activity
  • android.label – display name for the activity
  • intent-filter – under what conditions the activity will be displayed
  • receiver – non-activities that should be triggered under certain conditions
  • provider – components that supply data to activities
  • services – longer running code that can operate independently
image

No comments:

Post a Comment