Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Learning Android Application Development
Learning Android Application Development

Learning Android Application Development: Start building for the world's most popular mobile platform

Arrow left icon
Profile Icon Ràfols Montane Profile Icon Dawson
Arrow right icon
Mex$504.99 Mex$721.99
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.7 (3 Ratings)
eBook Aug 2016 320 pages 1st Edition
eBook
Mex$504.99 Mex$721.99
Paperback
Mex$902.99
Subscription
Free Trial
Arrow left icon
Profile Icon Ràfols Montane Profile Icon Dawson
Arrow right icon
Mex$504.99 Mex$721.99
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.7 (3 Ratings)
eBook Aug 2016 320 pages 1st Edition
eBook
Mex$504.99 Mex$721.99
Paperback
Mex$902.99
Subscription
Free Trial
eBook
Mex$504.99 Mex$721.99
Paperback
Mex$902.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learning Android Application Development

Chapter 2. Activities and Fragments - The Backbone of Your App

Activities and fragments are two of the most important concepts for an Android developer to master. In fact, in just about any Android-related programming interview, a common starting question is to ask a candidate to describe and outline activities, fragments, and their respective life cycles!

Broadly speaking, most Android apps consist of a series of connected screens that a user is able to navigate through. Obviously, more complex apps can be offered additional functionality such as background services, cloud messaging, broadcast receivers, and so on. However, the core UI will usually be centered around navigating through a series of connected activities or fragments nested within an activity.

A simple example of this basic UI in, for instance, a cooking-recipe application, would be a screen displaying a list of available recipes (Recipe List Activity) and another screen displaying details of each recipe (Recipe Detail...

Activities

Google describes an activity as an application component that provides a screen for a user to interact with. An Activity can be used to display information, call someone, or to even play a game. As mentioned earlier, a typical Android app consists of multiple activities and allows a user to navigate through them (an example of this is shown in the following screenshot). These Activities represent the basic building blocks of an application and knowing how to create and manage activities is fundamental to Android development. The following screenshot shows an example of navigating from a list activity to detail activity on an Android device. For more information, visit http://developer.android.com/guide/components/activities.html.

Activities

Each activity can contain a set of views and even fragments presenting information to users and to allow users to interact with the application. The preceding list-detail pattern is common among Android apps and can be seen in the stock apps provided...

Creating activities

Now that we have gone through the essentials and covered the activity boilerplate introduction, we can actually begin to have some fun and create our first activities! In this simple example, we will cover how to launch an activity and show how to extend the Activity super class to create an instance of our own activity. This will be a very simple introductory example and should not take more than 20-25 minutes to complete. So grab a coffee and let's get started!

Defining your activity

In the previous chapter, we introduced the Android App Manifest (AndroidManifest.xml) that contains essential information such as the package name and components of an application. For each activity in your application, you must create a corresponding entry in the app manifest along with additional information such as theme of the activity.

Creating an entry in the manifest is easy and you will only need the name of your activity in this example. You also need to add your activities...

Fragments

Informally, fragments are UI building blocks and are analogous to activities. They can be treated as subactivities and multiple fragments can be placed in a single activity. Fragments can represent screens within an application and are typically associated with a particular task such as a map fragment. Fragments can also exist within fragments to allow module portions of activities to be easily reused. Google formally defines a fragment as a piece of an application's user interface that can be placed in an activity (http://developer.android.com/reference/android/app/Fragment.html). Like activities, fragments have their own life cycles complete with similar callback events to use when implementing custom fragments. Fragments can also be placed on a stack for activity-like navigation through an app, complete with back button support.

Definitions and introductions aside, fragments are one of the most useful concepts to master in Android and they will make your life much easier...

Creating fragments

As with activities, now that we have covered the same old dry introduction to fragments, we can actually begin to use them! In the following sections, we will cover how to create fragments, create a static Fragment constructor, and instantiate a fragment that binds one or several fragments into a single parent activity.

Creating our own fragment

As we did in the activity example, perform the following steps:

  1. Open the Project tab on the right-hand side of the screen.
  2. Right-click on the com.example folder.
  3. Go to NewJava Class and name the class SampleFragment.

As all custom activities extend the class Activity, all custom fragments extend the class Fragment.

Note

If you are using the support library, you can choose to either use the Fragment class built into Android as of Honeycomb (API v11) or the android.support.v4.app.Fragment class bundled as part of the support library. If you are planning on supporting devices pre-ICS (API v14), you must...

Navigating through an app

In this section, we will cover how to navigate between fragments in your app. To keep things simple for the chapter, we will build upon our existing SampleActivity example and show how to add simple navigation to our application.

Activity navigation

Navigating between activities is one of the simplest actions that you can perform and is very commonly used. In the following example, we will show how to move from one instance of our SampleActivity (which we will refer to as activity A) to another instance of SampleActivity (which we will refer to as activity B). As we have already added the SampleActivity to our Android app manifest, we do not need to add an additional entry.

First, we will start by modifying the layout file to add an extra view. This view is a Button, and we will hook up this button to perform the activity navigation. The updated layout file should look like this:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res...

Activities


Google describes an activity as an application component that provides a screen for a user to interact with. An Activity can be used to display information, call someone, or to even play a game. As mentioned earlier, a typical Android app consists of multiple activities and allows a user to navigate through them (an example of this is shown in the following screenshot). These Activities represent the basic building blocks of an application and knowing how to create and manage activities is fundamental to Android development. The following screenshot shows an example of navigating from a list activity to detail activity on an Android device. For more information, visit http://developer.android.com/guide/components/activities.html.

Each activity can contain a set of views and even fragments presenting information to users and to allow users to interact with the application. The preceding list-detail pattern is common among Android apps and can be seen in the stock apps provided...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Get started with Android development, from the installation of required tools to publishing to the market
  • Make your applications Android N ready—Android has evolved quite a lot since the very beginning and so has their Software Development Kit—so get up to speed
  • Save time and improve the quality of your applications with widely used open source libraries and dependency management

Description

The mobile app market is huge. But where do you start? And how you can deliver something that takes Google Play by storm? This guide is the perfect route into Android app development – while it’s easy for new apps to sink without a trace, we’ll give you the best chance of success with practical and actionable guidance that will unlock your creativity and help you put the principles of Android development into practice. From the fundamentals and getting your project started to publishing your app to a huge market of potential customers, follow this guide to become a confident, creative and reliable mobile developer. Get to grips with new components in Android 7 such as RecyclerView, and find out how to take advantage of automated testing, and, of course, much, much more. What are you waiting for? There’s never been a better time – or a better way – to get into Android app development.

Who is this book for?

Want to get started with Android development? Start here.

What you will learn

  • Get to know how to use popular open source libraries to reduce time to market and avoid re-inventing the wheel
  • Automate your application's testing phase to avoid last minute crashes
  • Use dependency management to properly keep dependencies and updates under control
  • Efficiently show huge amounts of items in a list
  • Forget about memory and speed concerns
  • Publish and monetize your Android applications on Google Play
  • Persist your application data so it can continue working in offline mode
  • Don't let the UX break because of network issues

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Aug 30, 2016
Length: 320 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553846
Vendor :
Google
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Aug 30, 2016
Length: 320 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553846
Vendor :
Google
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Mex$85 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Mex$85 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Mex$ 3,036.97
Learning Android Application Development
Mex$902.99
Android Design Patterns and Best Practice
Mex$1004.99
Android Programming for Beginners
Mex$1128.99
Total Mex$ 3,036.97 Stars icon

Table of Contents

10 Chapters
1. Getting Started with Android Development Chevron down icon Chevron up icon
2. Activities and Fragments - The Backbone of Your App Chevron down icon Chevron up icon
3. Working with Views – Interacting with Your App Chevron down icon Chevron up icon
4. Lists and Adapters Chevron down icon Chevron up icon
5. Remote Data Chevron down icon Chevron up icon
6. Image Management Chevron down icon Chevron up icon
7. Permanent Data Chevron down icon Chevron up icon
8. Testing Your Application Chevron down icon Chevron up icon
9. Publishing Your Application Chevron down icon Chevron up icon
10. Monetization – Make Money with Your App Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.7
(3 Ratings)
5 star 0%
4 star 33.3%
3 star 33.3%
2 star 0%
1 star 33.3%
Sandeep Jan 17, 2017
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
good if you want to android development :)
Amazon Verified review Amazon
Amazon Customer Sep 20, 2016
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
It's like the writer is explaining his code but not the android system itself. Chapter one started with huge FragmentTransaction. The book used FragmentManager class but do not specify why. People needs to know why each subclass is used.
Amazon Verified review Amazon
James Mar 10, 2017
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Clearly, this is one of the worst technical books I've ever had a chance to read. I received it, browsed it for a few minutes and immediately set about to return it.Save your money, you can get a lot more information from the android developer official training site.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.