Get a free year on Tuts+ this month when you purchase a Siteground hosting plan from $3.95/mo
In this series, we've begun learning how to develop Android applications from scratch. We started exploring the development tools, got acquainted with the basic elements in an application project, looked at user interface design, interactivity, resources, and data, and we've also took a closer look at what happens when your application is running. What we've covered so far should put you in a good position to get started creating functional Android applications, but Android has a lot more to offer so the range of possibilities is virtually endless. You may therefore struggle to choose what to learn next. In this part, we'll wrap up the series by pointing out some possible directions for future learning. After this, the final part will be a quiz on what we covered throughout the series.
There are lots of possible directions you can take for building on the Android foundation you have gained by reading this series. Of course, if you have particular projects planned, then these will dictate some of what you will learn next. However, there is a lot to the Android platform, with many application elements common to most of the projects you will work on. In this tutorial, we'll zoom in on some of the most useful topics to look at to start building your Android skill set.
You can use the simple application project we created earlier in this series to try out the new Android skills you will learn. Remember that we tried saving data to the shared preferences. You could improve that example by saving data to a file. Try letting the user submit and save data by leveraging an
EditText view and a button. Write the user's data to a file, read it back in when the application launches, and display it in a
TextView view. This way you can save persistent data which will appear next time the application is run.
Another essential skill is retrieving data from a remote resource, such as a web service. To accomplish this, add an inner
AsyncTask class to your
Activity class in which you fetch the remote data. When the data is retrieved, display it in your application. Additionally, you may want to parse or format the data if the data your application receives is
JSON, or another common format. See Connecting to the Network for sample code you can use as a starting point.
The other main data storage option you are likely to find useful in many apps is using a SQLite database. Try this out by creating a
SQLiteOpenHelper class, in which you define the architecture of the database, such as tables and columns. Elsewhere in the application, you can then tell the
SQLiteOpenHelper to write data to the database and to read from it using a cursor, presenting the results in your application's user interface. Again, you may want to try letting the user enter data to save in the database and present the results on future runs of the application. In addition to inserting records and querying the database, try updating and deleting records as wel. See Saving Data in SQLite Databases for more information and sample code to get you started.
2. App Screens
In the application we created, we used a single screen in the user interface screen. Try adding to this by creating a second activity class in your app using the File > New > Class menu option. Add a button to the first screen, the main activity, which launches the second activity when the user taps it. For example, if the application would be a game, the button could read "How to Play" and the second activity could be named
How.java. Create a layout file for the second activity, including a
TextView with text stored in the
res/values strings XML file. If the application would be a game, the second activity could contain information about how to play the game. Many of the information sections in your applications will use this simple pattern.
onClick handler in the first activity, you can launch the "How to Play" activity using intents. Visit Starting Another Activity for more information about this. Once you have a second activity in your application, try passing data to it from the first activity using the
putExtra method. You can also try starting an activity for a result, letting the second activity do something, and then return data to the first one. You can retrieve the result data in the
onActivityResult method of the first activity. Take a look at the Activity class reference for an example of this.
As a next step, you could try to include some of the different user interface views in your activities. You will notice that different types of views require different approaches to implement them. Once you've got a good grasp of using different view types, try using fragments so you can start reusing parts of the user interface in various places of your application.
Another user interface component you'll find useful is the list View. With a list View, the screen presents a list of items. The list view is populated from a data source using an adapter, which maps data to views. You can use a
ListActivity instead of a standard
Activity class for this. In a list activity, you can override set methods for responding to user interaction with the items in a list, which makes the list a useful component for many application types. Visit List View for a functional example implementing a list view.
Applications with a look and feel that is consistent with the Android system itself tend to perform better. Whenever possible, you should try to use standard Android user interface elements rather than creating your own custom components. For this reason, you may want to try getting acquainted with the Action Bar and keep in mind whenever you design the user interface and navigation model of your applications.
You can create Android applications using various types of media, such as audio and video, animation and image capturing through the device's camera, including video capture. The Android system provides standard methods you can use to access resources, such as the camera, with actions for specific tasks including video recording. Browse the Multimedia guide of the Developer Guide for more information.
As we saw earlier in this series, you can build visual elements within your Android applications using XML to create shape drawables. You can also use XML to define animations with code controlling how the animations elapse. Animations on Android let you add dynamic effects to your user interface,with a variety of supported effects, such as fading, rotating, flipping, and various other transition types (Adding Animations).
4. Interacting with Other Applications
One of the benefits of developing on Android is that you can make use of existing resources of the platform, including other applications. As I mentioned earlier in this series, you can share data with other applications and make use of that shared data in your own applications. You can also let users share content from your applications using email, messages, and social networks. The simplest and most reliable way of doing this is via the send intent. When your applications launches a send action, the operating system will present a list of the applications the user can send content to. Be sure to read up on this topic in the Sending Simple Data to Other Apps guide, which also includes examples.
The send action is one example of launching facilities on Android from your own applications, but there are lots of ways in which you can accomplish this so make sure to try some of them in your own projects. For example, you can use the dial action to dial a number, and the view action to view web pages in the browser, or locations in the Maps application. You can also retrieve data from the device's built-in sensors, letting your application capture and process location and environmental data. In many cases, you can trigger these actions in ways that return information back to your application when the launched action is finished, creating a dialog between your application and the Android context. This way, your application fully exploit the mobile nature of the Android device.
We've touched on several potential topics for future learning, but in reality we have barely scratched the surface of what's possible on the Android platform. The platform is constantly changing and the list of what is possible is growing ever longer. The recommended techniques for common tasks change regularly as well so it is vital to keep learning if you want to continue developing high quality Android applications.
Here are some useful resources to bookmark:
- Visit the Android Developers Blog for new and upcoming platform features. The blog often includes functional code examples that you can learn from.
- The Vogella Android Tutorials are one of the most valuable Android learning resources on the web. The Vogella website often includes complete examples of techniques only covered in excerpts on the official Developer Guide.
- The Android Developers on Google+ is a good place to read up on announcements and discussions on Android development.
As with any development platform, you will find yourself with plenty of questions when you learn Android, most of which will lead you to a Google search. As you'll learn, many common questions have been answered comprehensively on Stack Overflow so you will soon become accustomed to visiting Stack Overflow if you aren't already.
In this series of tutorials, my goal has been to teach you the basics of Android development. If you've learned any programming or development skill in the past, you know that the learning process does not end here. If you plan to continue developing for the Android platform, you'll be able to build on what we've learned in this series, adding to your Android toolbox as you go. To finish this series up, the next installment will be a quiz testing you on what you've learned so far. Be prepared!