GithubHelp home page GithubHelp logo

headfirstandroid's Introduction

Table of contents

Chapter 1: Getting started

Android has been taking the world by storm. Everybody wants a smart phone or tablet, and Android devices are hugely popular. In this book we’ll teach you how to develop your own apps, and we’ll start by getting you to build a basic app and run it on an Android Virtual Device. Along the way you’ll meet some of the basic components of all Android apps such as activities and layouts. All you need is a little Java know-how…

Apps you'll build:

MyFirstApp

img

Chapter 2: Building Interactive Apps

Most apps need to respond to the user in some way. And in this chapter you’ll see how you can make your apps a bit more interactive. You’ll see how you can get your app to do something in response to what the user does, and how to get your activity and layout talking to each other like best buddies. And along the way we’ll take you a bit deeper into how Android actually works by introducing you to R, the hidden gem that glues everything together.

Apps you'll build:

BeerAdviser

img

Chapter 3: Multiple activities and intents

Most apps need more than one activity. So far we’ve just looked at single-activity apps, which is fine for simple apps. But when things get more complicated, just having the one activity won’t cut it. We’re going to show you how to build apps with multiple activities, and how you can get your apps talking to each other using intents. We’ll also look at how you can use intents to go beyond the boundaries of your app and make activities in other apps on your device perform actions. Things just got a whole lot more powerful…

Apps you'll build:

Messenger

img

Chapter 4: The activity lifecycle

Activities form the foundation of every Android app. So far you’ve seen how to create activities, and made one activity start another using an intent. But what’s really going on beneath the hood? In this chapter we’re going to dig a little deeper into the activity lifecycle. What happens when an activity is created and destroyed? Which methods get called when an activity is made visible and appears in the foreground, and which get called when the activity loses the focus and is hidden? And how do you save and restore your activity’s state?

Apps you'll build:

Stopwatch

img

Chapter 5: The user interface

Let’s face it, you need to know how to create great layouts. If you’re building apps you want people to use, you need to make sure they look just the way you want. So far we’ve only scratched the surface when it comes to creating layouts, so it’s time to look a little deeper. We’ll introduce you to more types of layout you can use, and we’ll also take you on a tour of the main GUI components and how you use them. By the end of the chapter you’ll see that even though they all look a little different, all layouts and GUI components have more in common than you might think.

img

Chapter 6: List views and adapters

Want to know how to best structure your Android app? You’ve learned some of the basic pieces that are user to build apps, and now it’s time to get organized. In this chapter we’ll show you how you can take a bunch of ideas and structure them to build an awesome app. We’ll show you how lists of data can form the core part of your app design, and how linking them together can create a powerful and easy-to-use app. Along the way, you get your first glimpse of using event listeners and adapters to make your app more dynamic.

Apps you'll build:

Starbuzz

img

Chapter 7: Fragments

You’ve seen how to create apps that work in the same way irrespective of the device they’re running on. But what if you want your app to look and behave differently depending on whether it’s running on a phone or a tablet? In this chapter we’ll show you how to make your app choose the most appropriate layout for the device screen size. We’ll also introduce you to fragments, a way of creating modular code components that can be reused by different activities.

Apps you'll build:

Workout

img

Chapter 8: Nested fragments

You’ve seen how using fragments in activities allow you to reuse code and make your apps more flexible. In this chapter we’re going to show you how to nest one fragment inside another. You’ll see how to use the child fragment manager to tame unruly fragment transactions. And along the way you’ll see why knowing the differences between activities and fragments is so important.

Apps you'll build:

Workout (updated)

img

Chapter 9: Action Bars

Everybody likes a shortcut. And in this chapter you’ll see how to add shortcuts to your apps using action bars. We’ll show you how to start other activities by adding action items to your action bar, how to share content with other apps using the share action provider, and how to navigate up your app’s hierarchy by implementing the action bar’s Up button. Along the way you’ll see how to give your app a consistant look and feel using themes, and introduce you to the Android support library package.

Apps you'll build:

BitsAndPizzas

img

Chapter 10: Navigation Drawers

Apps are so much better when they’re easy to navigate. In this chapter we’re going to introduce you to the navigation drawer, a slide-out panel that appears when you swipe your finger or click an icon on the action bar. We’ll show you how to use it to display a list of links that take you to all the major hubs of your app. You’ll also see how switching fragments makes those hubs easy to get to and fast to display.

Apps you'll build:

BitsAndPizzas (updated)

img

Chapter 11: SQLite databases

If you’re recording high scores or saving tweets, your app will need to store data. And on Android you usually keep your data safe inside a SQLite database. In this chapter, we’ll show you how to create a database, add tables to it, and prepopulate it with data, all with the help of the friendly SQLite helper. You’ll then see how you can cleanly roll out upgrades to your database structure, and how to downgrade it if you need pull any changes.

Apps you'll build:

Starbuzz (updated)

img

Chapter 12: Cursors and AsyncTasks

So how do you connect your app to a SQLite database? So far you’ve seen how to create a SQLite database using a SQLite helper. The next step is to get your activities to access it. In this chapter you’ll find out how to use cursors to get data from the database, how to navigate through cursors and how to get data from them. You’ll then find out how to use cursor adapters to connect them to list views. Finally, you’ll see how writing efficient multi-threaded code with AsyncTasks will keep your app speedy.

Apps you'll build:

Starbuzz (updated errr... again)

img

Chapter 13: Services

There are some operations you want to keep on running irrespective of which app has the focus. As an example, If you start playing a music file in a music app, you probably expect it to keep on playing when you switch to another app. In this chapter you’ll see how to use Services to deal with situations just like this. Along the way you’ll see how use some of Android’s built-in services. You’ll see how to to keep your users informed with the notification service, and how the location service can tell you where you’re located.

Apps you'll build:

Joke Odometer

img

Chapter 14: Material Design

With API level 21, Google introduced Material Design. In this chapter we’ll look at what Material Design is, and how to make your apps fit in with it. We’ll start by introducing you to card views you can reuse across your app for a consistent look and feel. Then we’ll introduce you to the recycler view, the list view’s flexible friend. Along the way you’ll see how to create your own adapters, and how to completely change the look of a recycler view with just two lines of code.

Apps you'll build:

BitsAndPizzas (one more time)

img

Appendix 1: ART–The Android Runtime

Android apps need to run on devices with low powered processors and very little memory. Java apps can take up a lot of memory and because they run inside their own Java Virtual Machine (JVM), Java apps can take a long time to start when they’re running on low- powered machines. Android deals with this by not using the JVM for its apps. Instead it uses a very different virtual machine called the Android Runtime (ART). In this appendix we’ll look at how ART gets your Java apps to run well on a small, low-powered device.

Appendix 2: ADB–The Android Debug Bridge

In this book we’ve focused on using an IDE for all your Android needs. But there are times when using a command tool can be plain useful, like those times when Android Studio can’t see your Android device but you just know it’s there. In this chapter we’ll introduce you to the Android Debug Bridge (or adb), a command line tool you can use to communicate with the emulator or Android devices.

Appendix 3: The Android Emulator

Ever felt like you were spending all your time waiting for the emulator? There’s no doubt that using the Android emulator is useful. It allows you to see how your app will run on devices other than the physical ones you have access to. But at times it can feel a little… sluggish. In this appendix we’re going to explain why the emulator can seem slow, Even better, we’ll give you a few tips we’ve learned for speeding it up.

Appendix 4: Top Ten Things (We Didn't Cover)

Even after all that, there’s still a little more. There are just a few more things we think you need to know. We wouldn’t feel right about ignoring them, and we really wanted to give you a book you’d be able to lift without extensive training at the local gym. Before you put down the book, read through these tidbits.

Get the book

img

Head First Android Development cuts through the fog of dozens of components, hundreds of API calls and focuses on the core skills you need. Do you want a book that is more than simply a reproduction of the online documentation? A book that is more like a course, taking you step-by-step through the development of real applications, just as if an experienced Android developer was sitting right next to you? This book teaches Android development by getting you to do Android development.

For more information, go to http://dogriffiths.github.io/HeadFirstAndroid

Social Media

headfirstandroid's People

Contributors

dogriffiths avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

headfirstandroid's Issues

Question about Chapter1 MyFirstApp

Hi,

I followed the steps in the book to run the sample code provided by AndroidStudio, but when AVD running, the "MyFirstApp" did not show up. And the console did not show the same output as the book's

The output of my console

emulator: WARNING: VM heap size set below hardware specified minimum of 128MB
emulator: WARNING: Setting VM heap size to 384MB
Hax is enabled
Hax ram_size 0x60000000
HAX is working and emulator runs in fast virt mode.
console on port 5556, ADB on port 5557

No data in listView (DrinkCategoryActivity) using SimpleCursorAdapter

I am using the codes from chapter 12 starbuzz app, but if we tap on Drink in top category, the DrinkCategoryactivity(ListActivity) doesn't populate the UI with the drink values from the database using SimpleCursorAdapter

I have debug it many times, but didn't able to identify the bug. Please help me reslove this issue

Chapter 13 Odometer Request Dangerous Permissions for Marshmallow Causes Crash

When requesting permission for ACCESS_FINE_LOCATION, Android has declared this as "Protection Level: Dangerous", which means that starting with Android Marshmallow, the app must explicitly ask the user for permission before it can be used.

Because there wasn't a request for permission, this app crashes immediately on devices running Android Marshmallow. I have a solution that I believe is working correctly here: https://github.com/TBVanderley4545/Odometer.git. I added checkSelfPermissions in onCreate and onStart in MainActivity.java and implemented onRequestPermissionResult. I also added checkSelfPermission in OdometerService.java in onCreate() and onDestroy().

Thank you for writing your book. It's been a great help.

question about Activity lifecycle

Hi,When i read about Activity lifecycle in chapter 4,your book said when an Activity is paused and then rotated,how is the lifecycle going? Here i add a new button to StopWatch app,and when click the button,start a new Activity,and the new Activity‘s theme is Theme.Dialog,so when start the Activity,my StopWatchActivity is in onPause method,at this moment,I rotate my device,onStop->onDestroy->onCreate->onStart->onResume->onPause is called,but the book said onResume is not called,how to understand this?

Request to discribe how to let SQLiteOpenHelper work together with fragments

Finaly managed to complete your book and all the projects..
It was a very good course.
Now i want to combine the different chapters and this is wat i find:
of course i want to use a database so i make a SQLiteOpenHelper class
an then i want to make this work together with fragments. guess what, they dont want to work together because fragmens dont accept context.
So, pease tell me how to adapt a database to the workout app or to the bitsandpizza app

chapter 14th

Hello Sir

I am trying to open pasta card view with image and text as the pizza work , but I am having trouble. can you help me, or someone can help me.

Android Studio changes to activity.xml and content.xml

Updates to Android studio have broken some of the chapter projects. Currently I am stuck on Chapter 9 bits and pizzas, as the theme changes cause the app to crash. I can't find any answers for getting themes and action bar working with the projects, and future chapters continue working on the bits and pizzas app. Short of waiting for a new version of the book to appear, how can the projects be adjusted for current versions of Android Studio?

Exception after calling onDestroy() method in DrinkCategoryActivity.java in Chapter 12

A NullPointerException may occur in DrinkCategoryActivity.java from Chapter 12 after calling the onDestroy() method if "cursor" or "db" objects are null (e.g., after rotating the device when having the Drink Categories list on screen).

@Override public void onDestroy() { super.onDestroy(); cursor.close(); db.close(); }

Need to do a null check on variables "cursor" and "db".

Chapter 7 Link Fragments issue

I was progressing through the book until the Link Fragments section of chapter 7. The onAttach is depricated but I changed that. The code included on the site doesn't appear to be updated.When I click on an activity the detail does not appear. The listener is null from what I can determine from the debugger.

Problem in Chapter 7 with WorkoutListFragment

When I try running the app after creating the WorkoutListFragment class and adding it to the Activity_Main_XML, on my device, I get an error message and the app is terminated immediately. I have check the code, and it is correct, the same thing happens when I run it in the Emulator. I do not know what the problem is.

Bug in Chapter 7 Fragment Rotation

With the fix code from the section "Rotating the device breaks the app", there's still a rotation bug.
Put a few items in the back stack, rotate the device twice, then go through the back stack. Everything is defaulting to the 0 index item.
The problem is Fragment.onCreateView() only gets called for the visible fragment. So when you rotate it the second time, the hidden fragments don't have the proper value to write to the bundle, and end up writing 0.
I moved the code to retrieve the value from the saved Bundle to onCreate(), which gets called for the hidden and visible fragments, and it functions properly.

Chapter 9 - Action Bars

I'm unable to use name="AppTheme" parent="Theme.Holo.Light"
or
<style name="AppTheme" parent="Theme.Material.Holo">
ERROR:
Cannot resolve symbol
Validate resource references inside Android XML.

It seems as though the 2 themes required in this chapter aren't available with

import android.app.Activity;

I get the same error when I download your source files from GIT and attempt to run them. Do you know what substitute them I should I run in order to complete this chapter?

Even though I'm extending Activity Intelisense is only showing AppCombat themes in the styles.xml.

apps with fragments not working (for me atleast)

Hello, I've been trying to work through the book, and have run into an issue i can't figure out. In both chapter six and seven i simply can not seem to make the fragments work. No bugs are reported within android studio, and the apps will even run, but as soon as i click on a button, such as drinks in the starbuzz app, the app immediately crashes. I assume this is a issue with fragments.

To be sure it was not my own inexperience that caused the issue, i have even tried to copy the exact files from the github, and the exact same issue occurs. My android studio is fully updated, and i have followed all the advice i have found online, but still, same issue.

problem with the Stopwatch fragment in chapter 7

After entering all the code fore the fragment, I get a warning in the XML file on all the buttons about the onClick reference line:

Cannot resolve symbol 'onClickStart' (the same with the onClickStop and onClickRest)

Checks if the related method specified on the onClick XML attribute is declared in the related activity.

all the onClick handlers are present in the code exactly like in the original Stopwatch Activity.
for some reason it looks fore the onClick in the activity not the fragment, because I tried to use the code correction in the XML file but it only suggested the activity's not the fragments, and when I tried telling it to put it in the fragment I got a warning: "Stopwatch fragment is not acceptable" and the problem was not resolved.

License

I own the Book. It is of great help. I am interested in using all or parts of delayedmessageservice.java in my app. Is this open source, is there any license requirements.

BitAndPizzas Chapter 10

import android.support.v7.app.ActionBarDrawerToggle;
is now deprecated.

Is there a workaround for this? I'm unable to use it in Chapter 10.

Request.

Your Starbuzz cafe project was a very useful lesson that taught me how to use a number of methods. It also is a prototype for an ordering app, something that is much needed in supply and sales industries.
One very important thing I couldn't figure out is how to create a working set of subcategories. Your project only features 3 items in the top category. Can you show us how you would fill out the 2 other categories? I built a project that attempt this by adding categories as a column to the table I had to uncomment quite a few of your checks and, ultimately, the top category wouldn't display anything after I removed the position ==0 check. Items displayed in the additonal categories I added to the array.
Here's a snippet:

// if (position == 0) {  //commented this out because nothing would display except top category.
 Intent intent = new Intent(TopLevelActivity.this,ItemCategoryActivity.class);
                    intent.putExtra(ItemCategoryActivity.CATEGORYID, (int)id);
                    startActivity(intent);

and

 cursor = db.query("InventoryItem",
                              new String[]{"_id", "NAME"},
                               "categoryId = ?",
                              new String[] { Long.toString(categoryId) },
                              null, null, null, null);

Chapter11 Workout App crashes after selecting a workout

The workout list appears when I open the app, but the app crashes when I select a specific workout. I have followed the code exactly as it is in the 2nd edition book from Chapter 11. The app worked fine in Chapter 10, it's just not working after making changes for the stopwatch. I also am not getting any error messages when it crashes. I am using Android Studio 3.3.1. Any idea what could be going on?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.