A scenario can be if your app needs to store data. Like when a user registers then you can save the information for later use.
There can be other reasons also. For example if a user has weak or no network then your app can display the last saved data to the user. What is SQLite Database?
Android comes with a lighweight database which can be used with your apps. SQLite is an open source lighweight database.
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
Why use SQLite?
1. It’s lightweight – It uses a file to store data. So no processing time is needed and hence you conserve battery.
2. It’s fast and stable and can handle transactions.
3. It’s optimized for a single user.
How does SQLite store data?
Android creates a data folder for each app where the files reside. Two files are created to store the data.
Suppose your App Title changes based on the Fragment name. So if you have three fragments FragmentA, FragmentB and FragmentC then the title will be based on the Fragment being displayed.
Like if you are at FragmentA then the App title will become FragmentA and so on.
Now if you navigate from FragmentA to FragmentB and then click on back button how will you know which Fragment you are at.
To solve this problem you can add a OnBackStackChangedListener.
Let’s see the steps to do this. You can refer to the source code for this illustration here.
1. When you replace a fragment in the code then attach a name to it.
In the last article you saw how to use DrawerLayout to create NavigationDrawer. Once you have a NavigationDrawer you may want to handle the drawer open and close events.
Like if the DrawerLayout is open you may like to display a different title and also hide some menu items.
In order to handle such events you need to create a ActionBarDrawerToggle object and assign it as a Drawer Listener.
Follow the video and refer to the Source code here
These are the lines spoken by Terri Trespicio at a TED talk where she recommends to stop searching for passion and start doing stuff. Can’t agree with her more.
Our society is plagued with this philosophy and this idea sells quite well. Not to say that its wrong but you loose out opportunities in this process.
Instead its way better to focus your energy on the job at hand.
It’s a very thoughtful and inspiring talk and I will highly recommend it.
The navigation drawer is a panel that displays the app’s main navigation options on the left edge of the screen. It is hidden most of the time, but is revealed when the user swipes a finger from the left edge of the screen or, while at the top level of the app, the user touches the app icon in the action bar.
Say you have an e-commerce app. You can use the Navigation Drawer to display Categories and Sub Categories. Similarly for any app you can provide a set of shortcuts to the user.
How to add Navigation Drawer?
In order to add this you need to modify the layout xml file. To the layout xml file you need to add a Drawer Layout. You will need to add v4 support library, if you don’t have it.
In one of the earlier article you have seen how the back button works. The user can navigate through activity history by the back button click.
The up button is different. It allows you to traverse through the Activity hierarchy.
Let’s say you have MainActivity. From MainActivity you navigate to DetailActivity. Now if you have declared MainActivity to be a parent of DetailActivity then you can navigate back to it using an up button.
To illustrate this I have added a DetailActivity to the ThemeDemoApp, as shown in the video.
Please follow the video to understand this better and you can refer to the source code for the example App here.
“If you can explain the WHY of things then that makes a huge difference to People’s Motivation. They understand Purpose. Process of Learning and how it should be. Make it interesting.” – Elon Musk
As Elon Musk has rightly said answer to the above question can be very useful to build and keep your interest to Learn something.
Elon also mentions the use of Gamification to make learning fun.
Here is a video in which Elon Musk talks about this and more at the Khan Academy.