Android Handbook
Post date: Feb 21, 2017 11:32:52 AM
App Restriction:
From API 26 or Android 8.0
Layout:
Linear Layouts is a view group that aligns all children in a single direction, vertically or horizontally
Relation Layouts is a view group that displays child views in relative positions
Recycler View
List View
Grid View
Intent Types:
Explicit intents specify the component to start by name (the fully-qualified class name). You'll typically use an explicit intent to start a component in your own app, because you know the class name of the activity or service you want to start. For example, you can start a new activity in response to a user action or start a service to download a file in the background.
Implicit intents do not name a specific component, but instead declare a general action to perform, which allows a component from another app to handle it. For example, if you want to show the user a location on a map, you can use an implicit intent to request that another capable app show a specified location on a map.
Activity:
Fragments:
A Fragment represents a behavior or a portion of user interface in an Activity.
Fragment is added
onAttach()
onCreate()
onCreateView()
onActivityCreated()
onStart()
onResume()
Fragment is active
onPause()
onStop()
onDestroyView()
onDestroy()
onDetach();
Fragment is destored()
Loader:
Loader API lets you load data from a content provider or other data source for display in an Activity or Fragment.
Services
Scheduled -> JobScheduler API
Started -> Activity calls startService() -> Broad casting
Usually, a started service performs a single operation and does not return a result to the caller
Bound -> Activity call bindService() -> Client - Server
A bound service runs only as long as another application component is bound to it. Multiple components can bind to the service at once, but when all of them unbind, the service is destroyed
A service runs in the main thread of its hosting process; the service does not create its own thread and does not run in a separate process unless you specify otherwise
onStartCommand()
The system invokes this method by calling startService() when another component (such as an activity) requests that the service be started. When this method executes, the service is started and can run in the background indefinitely
onBind()
The system invokes this method by calling bindService() when another component wants to bind with the service (such as to perform RPC). In your implementation of this method, you must provide an interface that clients use to communicate with the service by returning an IBinder. You must always implement this method; however, if you don't want to allow binding, you should return null.
onCreate()
The system invokes this method to perform one-time setup procedures when the service is initially created (before it calls either onStartCommand() or onBind()). If the service is already running, this method is not called.
onDestroy()
IntentService
This is a subclass of Service that uses a worker thread to handle all of the start requests, one at a time
If the system kills the service after onStartCommand() returns, do not recreate the service unless there are pending intents to deliver
Music player -> will restart, but not persist data
Download and upload process -> Restart and perceive the data
Broadcasts:
Sending broadcasts
The sendOrderedBroadcast(Intent, String) method sends broadcasts to one receiver at a time. As each receiver executes in turn, it can propagate a result to the next receiver, or it can completely abort the broadcast so that it won't be passed to other receivers. The order receivers run in can be controlled with the android:priority attribute of the matching intent-filter; receivers with the same priority will be run in an arbitrary order.
The sendBroadcast(Intent) method sends broadcasts to all receivers in an undefined order. This is called a Normal Broadcast. This is more efficient, but means that receivers cannot read results from other receivers, propagate data received from the broadcast, or abort the broadcast.
The LocalBroadcastManager.sendBroadcast method sends broadcasts to receivers that are in the same app as the sender. If you don't need to send broadcasts across apps, use local broadcasts. The implementation is much more efficient (no interprocess communication needed) and you don't need to worry about any security issues related to other apps being able to receive or send your broadcasts.
Broadcast receiver:
BroadcastReceiver