Xamarin Mobile Application Development for Android - Second Edition

Book description

Develop, test, and deliver fully-featured Android applications using Xamarin

About This Book

  • Build and test multi-view Android applications using Xamarin.Android
  • Work with device capabilities such as location sensors and the camera
  • A progressive, hands-on guide to develop stunning Android applications using Xamarin

Who This Book Is For

If you are a C# developer who wants to develop Android apps and enhance your existing skill set, then this book is ideal for you. Good working knowledge of C#, .NET, and object-oriented software development is assumed.

What You Will Learn

  • Build a multi-view, orientation-aware Android application with navigation
  • Lay out content using the LinearLayout, RelativeLayout, and TableLayout layout managers
  • Use a ListView (AdapterView) and Adapter to build a view that is populated from server data
  • Consume REST web service to perform GET, UPDATE, DELETE operation
  • Use Android SQLite for data persistence and caching
  • Capture the current location of a device, determine the street address, and integrate with the map app
  • Test, debug, and deploy an Android app

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 learn the fundamentals of Android app development using C# and Xamarin.Android. It will lead you through building an Android app step-by-step with steadily increasing complexity.

Beginning with an overview of the Android and Xamarin platforms to provide you with a solid understanding of the underlying platform, we gradually walk through building and testing a Points of Interest Android app using C# and the Xamarin.Android product. You will learn to create ListView and add detail view to your Android application. You will handle application behaviors on orientation changes, before learning the different techniques to manage resources and layouts to support multiple screen sizes. You will then access a SQLite database in a cross-platform way and add location features to your application. Finally, you will add camera integration to your application and deploy your app to the various Android app stores.

Style and approach

An example-oriented, comprehensive guide to gain an understanding of both the Android and Xamarin platforms.

Table of contents

  1. Xamarin Mobile Application Development for Android Second Edition
    1. Table of Contents
    2. Xamarin Mobile Application Development for Android Second Edition
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      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. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. The Anatomy of an Android App
      1. The Android platform
        1. Versions of Android
        2. The Linux kernel
        3. Native libraries
        4. The Android runtime
      2. The application framework
        1. The application layer
      3. The building blocks of the Android application
        1. The Android packages (.apk)
        2. The application manifest
        3. Activities
          1. The life cycle of an activity
          2. The events of an activity
        4. Fragments
          1. The fragment life cycle
        5. Services
        6. Content providers
        7. Broadcast receivers
        8. Views and ViewGroups
        9. Declarative versus programmatic View creation
        10. User interface widgets
        11. Common layouts
        12. Adapter layouts
        13. XML layout files
          1. Element and attribute names
          2. The View and layout identifiers
        14. Using XML layouts from activities
        15. Intents
        16. Resources
        17. The R.java file
      4. Summary
    9. 2. The Xamarin.Android Architecture
      1. Getting started with Xamarin
      2. Why Xamarin.Android?
        1. The benefits of using Xamarin.Android
        2. The drawbacks of using Xamarin.Android
      3. What is Mono?
      4. Mono and Dalvik side by side
        1. The Java Native Interface
        2. Peer objects
        3. Xamarin.Android application packaging
      5. The Android bindings design
        1. Design principles
        2. C# properties
        3. Delegates
        4. Constants to enumerations
      6. Development environments
        1. Xamarin Studio
        2. Xamarin for Visual Studio
        3. IDE comparison
        4. Compatibility
      7. Summary
    10. 3. Creating the Points Of Interest App
      1. The sample POIApp
      2. Installing Xamarin.Android
      3. Installing platforms and tools
        1. Tools
        2. The Android platform APIs
        3. The Android platform Extras
      4. Creating Android Virtual Devices
      5. Cloning a virtual device
      6. Speeding up the Android emulator
        1. Using the x86 emulator
        2. Third-party emulator solutions
          1. The Xamarin Android Player
          2. Genymotion
      7. Creating the POI app
      8. The Xamarin Studio IDE
      9. The Project Options view
        1. Understanding the project structure
      10. The Xamarin Studio layout designer
        1. The designer content layout
        2. The Document Outline and Properties pads
        3. Toolbox
        4. Setting the target framework
      11. Setting the app icon and package name
      12. The launcher activity
      13. Running and debugging the app
      14. Debugging with an Android device
        1. Enabling USB debugging
        2. Installing a USB driver
        3. Running apps on a device
        4. Behind the scenes
        5. The peer object
      15. The AndroidManifest.xml file
      16. Summary
    11. 4. Adding a List View
      1. Creating the POI ListView layout
      2. Creating POIListActivity
      3. Creating the POI list row 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
      4. Creating the PointOfInterest apps entity class
      5. Populating the ListView item
      6. Creating POIListViewAdapter
        1. Implementing a constructor
        2. Implementing Count { get }
        3. Implementing GetItemId()
        4. Implementing the index getter method
        5. Implementing GetView()
        6. Reusing row Views
      7. Populating row Views
        1. Populating the list thumbnail image
          1. Using UrlImageViewHelper
          2. Adding Internet permissions
      8. Hooking up POIListViewAdapter
      9. Consuming the web service
        1. An introduction to web services
        2. Deploying the POI web service
        3. Consuming REST web services asynchronously
        4. Creating the POIService class
        5. Asynchronous programming with async and await
        6. Serializing and deserializing using Json.NET
        7. Updating POIListActivity
      10. Adding actions to ActionBar
      11. Defining the menu XML file
      12. Setting menus in OnCreateOptionsMenu()
      13. Handling selection in OnOptionsItemSelected()
      14. Handling the ListView click event
      15. Handling no network condition
      16. Toast
      17. Summary
    12. 5. Adding a Details View
      1. Creating the POIDetail layout
        1. Understanding ScrollView
        2. Using the TableLayout manager
        3. Working with EditText's InputType
      2. Creating POIDetailActivity
      3. Adding navigation to POIDetailActivity
        1. Navigation on the POIList item click
      4. Receiving the data in POIDetailActivity
        1. Binding variables to controls
      5. Populating user interface widgets
      6. Adding the save and delete actions
        1. Disabling the delete action
      7. Adding the save and delete actions in POIService
        1. Consuming the web service to create or update a POI
        2. Adding the CreateOrUpdatePOIAsync method to POIService
        3. Consuming the web service to delete the POI
        4. Adding the DeletePOIAsync method to POIService
      8. Creating SavePOI()
      9. Creating DeletePOI()
      10. Adding validation
        1. Using the EditText.Error property
        2. Adding a delete confirmation prompt
      11. Refreshing POIListActivity
      12. Summary
    13. 6. Making Your App Orientation-aware
      1. The Android behavior on configuration changes
      2. Locking the Android application orientation
      3. Dynamically requesting the orientation
      4. Saving the activity state for configuration changes
        1. Manually saving the activity state
        2. Retaining the POI list scroll position
      5. Building the orientation-aware layout
      6. Manually handling the orientation behavior
      7. Summary
    14. 7. Designing for Multiple Screen Sizes
      1. An introduction to Android tablets
      2. Creating an Android tablet emulator
      3. An introduction to fragments
        1. Creating a new fragment
      4. Making POIApp compatible with Android tablets
      5. Using fragments for displaying POIDetails
        1. Creating the POIDetailsFragment layout
        2. Creating the POIDetailFragment
        3. Working with the save and delete actions
        4. Adding the POIDetailFragment to POIDetailActivity
          1. Modifying the POI details activity layout
          2. Refactoring POIDetailActivity to add POIDetailFragment
      6. Using the list fragment for displaying the POI list
        1. Understanding ListFragment
        2. Creating the POIListFragment layout
        3. Creating the fragment to display the POI list using POIListFragment
        4. Adding POIListFragment to POIListActivity
          1. Modifying the POI list activity layout
          2. Adding POIListFragment to POIListActivity
      7. Creating a multi-pane layout for tablets
      8. Updating the POIApp to support the multi-pane split layout
      9. Working with DialogFragment
      10. Fragments for older Android devices
      11. Handling configuration changes with fragments
      12. Summary
    15. 8. Creating Data Storage Mechanisms
      1. Data storage in Android
        1. Shared preferences
        2. The SQLite database storage
      2. Using the SQLite.net ORM component
        1. Using attributes to mark POIApp to be persisted
        2. Adding a database helper class
          1. Creating or updating the POI record
          2. Reading POI details from the database
          3. Deleting the POI data from the database
      3. Using the Xamarin.Android NUnitLite
        1. Setting up for tests
        2. Creating the test methods
          1. The CreatePOI test
          2. The DeletePOI test
        3. Executing the tests
      4. Implementing the caching logic to POIApp
      5. Summary
    16. 9. Making POIApp Location Aware
      1. Working with location services
        1. Setting the app permissions
        2. Configuring the emulator
        3. Obtaining an instance of LocationManager
      2. Requesting location change notifications
        1. Implementing ILocationListener
      3. Adding location services to POIApp
        1. Adding location services to the POI list
        2. Adding location services to POI details
          1. Updating the user interface
          2. Adding the code
        3. Mocking location data for testing
        4. Getting an address for a location
        5. Keeping the user informed
      4. Adding map integration
        1. Navigating to the Map app
        2. Checking for registered map apps
      5. Summary
    17. 10. Adding the Camera App Integration
      1. Picking an integration approach
      2. Permissions and features
      3. Configuring the emulator
      4. Extending the data service
        1. Implementing GetFileName()
        2. Implementing GetImage()
        3. Implementing DeleteImage()
      5. Capturing an image from POIDetailFragment
        1. Adding UI elements
        2. Creating the camera Intent
        3. Checking for registered camera apps
        4. Providing additional information with the Intent
          1. Providing a filename and location
          2. Providing a size limit
        5. Starting the Intent
        6. Completing the NewPhotoClicked() method
        7. Processing the results of the Intent
      6. Upload an image using an HTTP multipart
      7. Summary
    18. 11. Publishing an App to the App Store
      1. Preparing the application for release
        1. Disabling the debug mode
        2. Configuring linking options
          1. Side effects of linking
        3. Selecting supported ABIs
        4. Verifying the package name, icon, and app version
          1. The package name
          2. The application name and icon
          3. The application versioning scheme
        5. Review user permissions
      2. Publishing a signed APK for uploading
        1. Android keystores
        2. Publishing from Xamarin.Android
        3. Republishing the app
      3. Different app distribution options
        1. Self-publishing via website links or e-mails
        2. Publishing on Google Play
        3. Third-party app stores
      4. Summary
    19. Index

Product information

  • Title: Xamarin Mobile Application Development for Android - Second Edition
  • Author(s): Nilanchala Panigrahy
  • Release date: August 2015
  • Publisher(s): Packt Publishing
  • ISBN: 9781785280375