Android architecture.png
Component | What It Does | Example |
---|---|---|
Activity base class: android.app.Activity | Holds, displays the user interface elements (View and ViewGroups). It’s a focused thing a user can do with your application | View a single e-mail message, take notes |
Service base class: android.app.Service | Run a process in the background | Download a large file from the Internet, play background music |
BroadcastReceiver base class: android.content.BroadcastReceiver | Receive messages either from the Android system or from applications | Display a warning message when the device battery dips to below 10% |
ContentProvider base class: android.content.ContentProvider | Store and retrieve data, like a database | Contacts or address book on your phone. Any application can look up and add data to the phonebook |
Design editor.png
Task | Windows or Linux | macOS |
---|---|---|
Open Settings or Preferences dialog | Ctrl + Alt + S | ⌘ + ',' |
Expand code block | Ctrl + Shift + '+' (plus) | (comma) ⌘ + '+' (plus) |
Collapse code block | Ctrl + Shift + '-' (minus) | ⌘ + '-' (minus) |
Constraint handles and sizing handles.png
Attributes inspector.png
Constraint inspectors.png
Activity Life cycle.png
Event | Description |
---|---|
onCreate | Called when the activity is first created; you can put your initialization codes here |
onRestart | When the activity has been stopped and restarted again. This is always followed by onStart |
onStart | When the activity is starting to become visible to the user |
onResume | The activity is ready to interact with the user, at this point; the activity is at the top of the activity stack, and it occupies the whole screen |
onPause | When the activity is about to go to the background; this can happen when another activity grabs the focus |
onStop | When the activity is no longer visible to the user |
onDestroy | Called when the activity is destroyed. For the application to come back, it needs to be created again |
https://www.materialpalette.com/l
www.materialpalette.com.png
AsyncTask and MainActivity.png
Parameter | Description |
---|---|
1st arg (Params) | What information do you want to pass to the background thread? This is usually the UI element(s) that you want to update. When you call execute from MainActivity, you will need to pass this parameter to the AsyncTask. This param automatically makes its way to the doInBackground method. In our example, this is a text view object. We want the background thread to have access to this UI element as it does its work |
2nd arg (Progress) | What type of information do you want the background thread to pass back to onProgressUpdate method so you can specify the status of a long running operation to the user? In our case, we want to update the text attribute of the text view, so this is a String object |
3rd param (Result) | What kind of data do you want to use to specify the status of doInBackground when it finishes the task? In our case, I just wanted it to return true if everything went well, so the third parameter is a Boolean |
Storage | Description |
---|---|
SharedPreferences | This is the simplest form of storage. It’s just a dictionary object that uses the key/value pair idiom. This is useful if your data is simple enough to be structured as a dictionary object (key/value pairs). Android stores these files internally as XML files. SharedPrefs only stores simple data types (e.g., String and primitive data types). It cannot store more complex data |
Internal or external storage | Stores data in the device storage (internal) or media storage like SDCARD (external). If you need to store data that is more complex in structure than a dictionary can afford (e.g., audio, video files), you may want to consider using this type of persistence mechanism |
SQLite database | This one uses a relational database. If you have worked with other databases before—MS SQL server, MySQL, PostgreSQL, or any other relational database—this is essentially the same. Data is stored in tables, and you need to use SQL statements to create, read, update, and delete data |
Network | If you can assume that your users will always have Internet access and you have a database server that is hosted on the Internet, then you can use this option. This setup can get a bit complicated because you will need to host the database somewhere (Amazon, Google, any other cloud provider), provide a REST interface for the data, and use an HTTP library as a client in the Android app. We won’t cover this topic in this book |
Content Providers | Content Provider is another component on the Android platform; it’s right up there with Activities, Services, and Broadcast receivers. This component makes data available to applications other than itself. Think of it like a database that has public HTTP API layer. Any application that communicates over HTTP can read and write data to it |