You are previewing Xamarin Mobile Application Development for Android.
O'Reilly logo
Xamarin Mobile Application Development for Android

Book Description

Get up to speed with mobile computing with this step-by-step guide to developing and testing an Android app using C# and Xamarin. From first principles to distribution, everything you need is here.

In Detail

Technology trends come and go, but few have generated the excitement, momentum, or long-term impact that mobile computing has. Mobile computing impacts people’s lives at work and at home on a daily basis. Many companies and individual developers are looking to become a part of the movement but are unsure how to best utilize their existing skills and assets. The Xamarin suite of products provides new opportunities to those who already have a significant investment in C# development skills and .NET code bases, and would like to enter into this new, exciting world.

This example-oriented guide provides a practical approach to quickly learning the fundamentals of Android app development using C# and Xamarin.Android. It will lead the readers through building an Android app step-by-step with steadily increasing complexity.

This book begins with an overview of the Android and Xamarin platforms to provide you with a solid understanding of the environment you will be working in. You will then be gradually walked through building and testing an Android app using C# and the Xamarin.Android product. You will learn the basics of interacting with some of the more interesting aspects of Android devices including location services, the camera, and maps. You will also be given the opportunity to work with three different layout managers to gain an understanding of the various options available for arranging controls and content. The book ends with a discussion on the final steps involved in preparing apps for deployment to the various Android app stores.

In a relatively short period of time, developers familiar with C# and rich client technologies such as WPF and Silverlight will be effectively developing, testing, and delivering Android apps.

What You Will Learn

  • Build a multi-view Android application with navigation
  • Utilize the ActionBar for app actions
  • Create a simple JSON-based persistent service to save data locally on the device
  • Lay out content using the LinearLayout, RelativeLayout, and TableLayout layout managers
  • Use a ListView (AdapterView) and Adapter to build a view that is populated by dynamic data
  • Capture the current location of a device and determine the street address
  • Integrate with the map app to display a point of interest
  • Capture and save a photo
  • Test, debug, and deploy an Android app
  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

    Table of Contents

    1. Xamarin Mobile Application Development for Android
      1. Table of Contents
      2. Xamarin Mobile Application Development for Android
      3. Credits
      4. About the Author
      5. About the Reviewers
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. The Anatomy of an Android App
        1. The Android platform
          1. Linux
          2. Native libraries
          3. The Android runtime
          4. The Application Framework
          5. Applications
            1. The Android packages (.apk)
            2. The application manifest
          6. Versions of Android
        2. The Android applications
          1. Activities
            1. The life cycle of an activity
            2. The states of an activity
            3. The events of an activity
          2. Services
          3. Content providers
          4. Broadcast receivers
          5. Views and ViewGroups
            1. Declarative versus programmatic View creation
            2. User interface widgets
            3. Common layouts
            4. Adapter layouts
          6. XML layout files
            1. Element and attribute names
            2. IDs
            3. Using XML layouts from activities
          7. Intents
          8. Resources
            1. The file
        3. Summary
      9. 2. Xamarin.Android Architecture
        1. Why Xamarin.Android?
        2. What is Mono?
        3. Mono and Dalvik side by side
          1. The Java Native Interface
            1. Peer objects
          2. Xamarin.Android application packaging
        4. The Android bindings design
          1. Design principles
          2. C# properties
          3. Delegates
          4. Constants to enumerations
        5. Development environments
          1. Xamarin Studio
          2. Xamarin for Visual Studio
          3. IDE comparison
          4. Compatibility
        6. Summary
      10. 3. Creating the Points of Interest App
        1. The sample app
        2. Installing Xamarin.Android
        3. Creating the app
          1. Xamarin Studio IDE
          2. The Project Options View
            1. Setting the target framework
            2. Setting the app icon and package name
          3. The initial activity
          4. Running and debugging the app
          5. Creating and customizing emulators
          6. Using the x86 emulator
          7. Debugging with an Android device
            1. Enabling USB debugging
            2. Installing a USB driver
            3. Running apps on a device
        4. Behind the scenes
          1. Peer object
          2. The AndroidManifest.xml file
        5. Summary
      11. 4. Creating a Data Storage Mechanism
        1. Creating the Point of Interest entity class
        2. Creating the POI storage interface
        3. Implementing the POI storage services
          1. Using Xamarin.Android NUnitLite
            1. Setting up for tests
            2. Creating the test methods
              1. The Create POI test
              2. The Update POI test
              3. The DeletePOI() test
            3. Executing the tests
          2. Json.NET
            1. Downloading Json.NET
          3. Implementing and testing the POIJsonService methods
            1. Implementing caching
            2. Implementing SavePOI()
            3. Implementing GetPOI()
            4. Implementing DeletePOI()
        4. Summary
      12. 5. Adding a List View
        1. Creating the POI ListView layout
          1. Adding a RelativeLayout view group
          2. Adding an ImageView widget
          3. Adding a LinearLayout widget
          4. Adding the name and address TextView classes
          5. Adding the Distance TextView
        2. Populating the ListView item
          1. Shared instance of IPOIDataService
            1. Permissions
          2. Creating POIListViewAdapter
          3. Implementing a constructor
          4. Implementing Count { get; }
          5. Implementing GetItemId()
          6. Implementing the index getter method
          7. Implementing GetView()
            1. Reusing row Views
            2. Populating row Views
          8. Hooking up POIListViewAdapter
        3. Adding actions to ActionBar
          1. Defining the menu .xml file
          2. Setting menus in OnCreateOptionsMenu()
          3. Handling selection in OnOptionsItemSelected()
        4. Configuring an SD card for the emulator
        5. Running POIApp
        6. Android Device Monitor
        7. Handling row clicks
        8. Summary
      13. 6. Adding a Detail View
        1. Creating the POIDetail layout
          1. Working with InputType
          2. Creating POIDetailActivity
          3. Binding variables to controls
        2. Adding navigation to POIDetailActivity
          1. Navigating on new action
          2. Navigating on POI Click
          3. Receiving data in POIDetailActivity
          4. Populating user interface widgets
        3. Adding Save and Delete actions
          1. Disabling the Delete action
          2. Creating SavePOI()
          3. Creating DeletePOI()
        4. Adding validation
          1. Using the EditText.Error property
        5. Adding a Delete confirmation prompt
        6. Toasting success
        7. Refreshing POIListActivity
        8. Wrapping up
        9. Summary
      14. 7. Making POIApp Location Aware
        1. Location services
          1. Setting app permissions
          2. Configuring the emulator
          3. Obtaining an instance of LocationManager
          4. Requesting location change notifications
            1. Implementing ILocationListener
          5. Adding location services to POIApp
            1. Adding location services to POIListActivity
            2. Adding location services to POIDetailActivity
              1. Updating the user interface
              2. Adding the code
            3. Getting an address for a location
            4. Keeping the user informed
            5. Dealing with configuration changes
              1. Saving and restoring a state
              2. Preventing activity destruction
        2. Adding map integration
          1. Navigating to the map app
            1. Checking for registered map apps
        3. Summary
      15. 8. Adding Camera App Integration
        1. Picking an integration approach
        2. Permissions and Features
        3. Configuring the Emulator
        4. Extending the data service
          1. Defining GetImageFilename()
          2. Implementing GetImageFilename()
          3. Updating DeletePOI()
        5. Capturing an image from POIDetailActivity
          1. Adding UI elements
          2. Creating the intent
          3. Checking for registered camera apps
          4. Providing additional information with the intent
            1. Providing a filename and location
            2. Providing size limit
          5. Starting the intent
            1. Completing the NewPhotoClicked() method
          6. Processing the results of the intent
        6. Displaying existing images in POIDetailActivity
        7. Displaying POI images in POIListActivity
        8. Summary
      16. 9. Deploying Your App
        1. App distribution options
        2. Preparing for a release APK
          1. Disabling debug
            1. AndroidManifest.xml
            2. AssemblyInfo.cs
          2. Linking
            1. Linking options
            2. Side effects of linking
          3. Selecting supported ABIs
        3. Publishing a signed APK
          1. Keystores
          2. Publishing from Xamarin.Android
          3. Republishing
        4. Summary
      17. Index