The Navigation Drawer is a panel where you can put your navigation options. The panel is hidden off-screen and displays when the user swipes it onto the screen.
You can also use the app icon as a button to open and close the drawer.
Using Swipe Views to swop pages
Swipe views allow you to change pages by swiping your finger across the screen.
You create Swipe views by using a page viewer and an adapter. The adapter supplies the pages and the page viewer takes care of moving the pages on and off the screen.
We’re using a ViewPager. It’s a layout manager that takes care of the horizontal scrolling. Usually it’s used with fragments, scrolling them on and off screen.
We’re also going to need a page adapter to supply the pages to the ViewPager.
As we’re using fragments, we have two adapter options:
We’re going to use the FragmentStatePagerAdapter.
Using Tab navigation in your apps
Tab buttons are displayed in the Action Bar. You can also use images instead of buttons or even your own custom views.
Tabs are designed to work with fragments. Use them to swop fragments in your activities.
We’ll show you how to use Tabs to swop fragments in your activity.
An activity is destroyed and recreated when a device’s configuration changes.
Usually the activity’s lifecycle takes care of saving and restoring its state. Sometimes you may need to restore lots of data. This could take some time resulting in a bad user experience.
Here’s where you can use fragments to retain an instance of your data. You can then get the data out of the fragment and rebuild your activity, super fast!
Be careful not to save objects that are tied to the activity; such as drawables, adapters, views or any other objects associated with a context. They’ll cause memory leaks – the object keeps a reference to the context (the activity for example), so it will remain in memory, leaving less for your app to use.
Have a look how easy it is to use a fragment to save an Object during a configuration change!
Preference Settings allow the user to select basic settings for an app. It’s a way of customising the app to suite the user.
This tutorial will show you how you can create your own custom Preference Settings for your apps.
We’ll be using fragments and Headers so this tutorial is suitable for apps developed for devices running Android 3.0 and up.
There are four parts to the Preference Framework. We’ll cover all of them:
Each Preference appears as an item in a list. The user is able to modify these preference settings.
Well, it’s sort of about context menus but different.
It’s all about using the contextual action mode. This lets the user do stuff with the items that they have selected.
Enabling the contextual action mode, displays a Contextual Action Bar at the top of the screen. You can then place action items, which are like menu options, on this bar.
The user selects items from a list for example, chooses an action item and the action linked to that action item is performed on all of the selected items.
Say you had a list of countries and you want the user to be able to select a couple of them to add to a database. This is where you could use the contextual action mode.
It enables the user to select one or more of the countries in the list. They can then select a Save action item, for example, and all the selected country items will be saved in the database.
We’ll show you how to:
This tutorial will show you how to:
You’ve probably used intents to start activities. You can also use intents to broadcast messages.
The broadcast intent carries information about who should receive the message and what should be done with it.
Broadcast Receivers can receive these messages.
This broadcast mechanism runs in the background. The user is not aware of it as Broadcast receivers don’t have a User Interface.
You can also use Broadcast receivers to do small bits of work which must complete within 5 seconds. If they don’t, then an Application Not Responding dialog appears.
Usually you would use a receiver to start other components like Services. You can also send a notification from the receiver.
Activities are application components that we, mostly, see as the screen. It displays images, text, buttons, etc. that we interact with. Some activities don’t display anything.
Apps usually have a number of activities. One is seen as the main activity. This is the first screen we see when the app starts.