- 1 CE Learning
- 2 Glossary
- 3 New Project Configuration
- 4 Folder Tree
- 5 Activity & Layout Name
- 6 Minimum SDK
- 7 Android Activity Lifecycle
- 8 Density Independent Pixels
New Project Configuration
Space, capital letters, i.e. "Demo App"
domain name i.e. "example.brandonphuong.net" Doesn't really matter that much at this point. All of this configuration can be changed later. All that really matters is that this config builds the package name.
Package Nameː company domain and application name in reverse i.e., "net.brandonphuong.example.demoapp"
Package name is used if your package is submitted to Google Play, so it must be unique. The package name removes spaces, capitals, etc.
2 main folder which should concern you.
Gradle is an OS build tool inside Android Studio application which AS uses to build from files in the folder tree. The gradle folder are just scripts. If we want, we can write scripts to customize work in the build process.
A collection of folders and files which make up your Android Application. 3 folders exist my default: manifests, res and java
AndroidManifests.xml contain basic details about our app, such as application icon, labels, app name, app theme, etc. Edit this later on.
Short for resources, contains things such as images, icons, or music our application needs. Inside res > layout > activity ̠ main.xml, this is where we'll see what it actually looks like.
This is where our main source code lives and runs. MainActivity file inside Java is where we:
- define our package (basically the package name)
- can import classes, or, bundles of codes.
- The first is android.support.v7.app.AppCompatActivity, compat is short for compatiblity, which makes sure our app is backwards compatible with as many android versions as possible.
- The second is android.os.Bundle, which is the operating system bundle, that allows us to work with the Android OS.
- And then, public class allows us to define our own class. In this example, we're defining MainActivity
Activity & Layout Name
Activity name is self explanatory, however it is without spaces, words , by default:MainActivity
Layout name is in reverse and separated by underscore, i.e, activity_name
Choose API 15 Android 4.0.3(IceCreamSandwich), or whichever will be most compatible with your target devices.
Android Activity Lifecycle
In Android OS, almost all apps start and end with an activity.
Activities get created, paused, stopped and destroyed. These lifecycle changes need to be handled gracefully.
There are many lifecycle methods.
Android OS is responsible for recreating the activity, therefore the developer is only responsible for saving and restoring the activity state.
For example, when screen orientation changes, activities are stopped and recreated. This is because orientations require different layouts and those layouts require different resources, activities are always recreated on an orientation change. By default, if you rotate the screen, an activity will be restarted, however if you hook into the right lifecycle events, we can save off the position when the activity stops and restore that position when it gets recreated, creating the illusion of seamlessness.
Saving Instance State
Density Independent Pixels
DP, pronounced 'dip' describes an attribute value of size results in a physical size that remains consistent across all devices regardless of varying pixel density. It's reccomended that all touch targets are at least 48x48dp.