Android SDK - nikitachebotarev/docs GitHub Wiki

Activity launch modes

  • standart (Default. The system always creates a new instance of the activity in the target task and routes the intent to it.)
  • singleTop (If an instance of the activity already exists at the top of the target task, the system routes the intent to that instance through a call to its onNewIntent() method, rather than creating a new instance of the activity.)
  • singleTask (The system creates the activity at the root of a new task and routes the intent to it. However, if an instance of the activity already exists, the system routes the intent to existing instance through a call to its onNewIntent() method, rather than creating a new one.)
  • singleInstance (Same as "singleTask", except that the system doesn't launch any other activities into the task holding the instance. The activity is always the single and only member of its task.)

Intent flags

  • FLAG_ACTIVITY_NEW_TASK (singleTask)
  • FLAG_ACTIVITY_SINGLE_TOP (singleTop)
  • FLAG_ACTIVITY_CLEAR_TOP (Instead of launching a new instance of that activity, all of the other activities on top of it are destroyed and this intent is delivered to the resumed instance of the activity)

Back stack attributes

  • alwaysRetainTaskState (The task retains all activities in its stack even after a long period.)
  • clearTaskOnLaunch (The task always removes all activities (except root activity) after user leaves, even after a leaving the task for only a moment.)
  • finishOnTaskLaunch (Like clearTaskOnLaunch but only for current activity)

Activity lifecycle

  • onCreate (This method receives the parameter savedInstanceState, which is a Bundle object containing the activity's previously saved state. If the activity has never existed before, the value of the Bundle object is null.)
  • onStart (The onStart() call makes the activity visible to the user, as the app prepares for the activity to enter the foreground and become interactive. )
  • onResume (This is the state in which the app interacts with the user. The app stays in this state until something happens to take focus away from the app. Such an event might be, for instance, receiving a phone call, the user’s navigating to another activity, or the device screen’s turning off.)
  • onPause (As long as the activity is still partially visible but not in focus, it remains paused.)
  • onStop (When your activity is no longer visible to the user, it has entered the Stopped state, and the system invokes the onStop() callback. This may occur, for example, when a newly launched activity covers the entire screen. The system may also call onStop() when the activity has finished running, and is about to be terminated.)
  • onSaveInstanceState
  • onDestroy (Is called before the activity is destroyed. The system invokes this callback either because: the activity is finishing (due to the user completely dismissing the activity or due to finish() being called on the activity), or the system is temporarily destroying the activity due to a configuration change (such as device rotation or multi-window mode). You can distinguish between these two scenarios with the isFinishing() method.)

Fragment lifecycle

  • onAttach()
  • onCreate(Bundle)
  • onCreateView(Bundle)
  • onActivityCreated(Bundle)
  • onStart()
  • onResume()
  • onPause()
  • onStop()
  • onSaveInstanceState()
  • onDestroyView()
  • onDestroy()
  • onDetach()

View lifecycle

  • onAttachedToWindow() (This is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before onDraw(android.graphics.Canvas), however it may be called any time before the first onDraw -- including before or after onMeasure(int, int).)
  • onDetachedFromWindow() (This is called when the view is detached from a window. At this point it no longer has a surface for drawing. If you override this method you must call through to the superclass implementation.)
  • onMeasure() (Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overridden by subclasses to provide accurate and efficient measurement of their contents. CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.)
  • onLayout() (Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.)
  • onFinishInflate() (Finalize inflating a view from XML. This is called as the last phase of inflation, after all child views have been added. Even if the subclass overrides onFinishInflate, they should always be sure to call the super method, so that we get called. If you override this method you must call through to the superclass implementation.)
  • onDraw(Canvas) (Implement this to do your drawing.)
  • invalidate() (reset to onDraw())
  • requestLayout() (reset to onMeasure())
  • onSaveInstanceState(return Parcelable) (Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can not be reconstructed later. For example, you will never store your current position on screen because that will be computed again when a new instance of the view is placed in its view hierarchy.)
  • onRestoreInstanceState(Parcelable) (Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState(). This function will never be called with a null state. If you override this method you must call through to the superclass implementation.)

Service methods

  • 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. If you implement this, it is your responsibility to stop the service when its work is complete by calling stopSelf() or stopService())
  • 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 (The system invokes this method when the service is no longer used and is being destroyed. Your service should implement this to clean up any resources such as threads, registered listeners, or receivers. This is the last call that the service receives.)

Work manager

  • Work Constraints (Declaratively define the optimal conditions for your work to run using Work Constraints. (For example, run only when the device is Wi-Fi, when the device idle, or when it has sufficient storage space, etc.))
  • Robust Scheduling (WorkManager allows you to schedule work to run one- time or repeatedly using flexible scheduling windows. Work can be tagged and named as well, allowing you to schedule unique, replaceable, work and monitor or cancel groups of work together. Scheduled work is stored in an internally managed SQLite database and WorkManager takes care of ensuring that this work persists and is rescheduled across device reboots.)
  • Flexible Retry Policy (Sometimes work fails. WorkManager offers flexible retry policies, including a configurable exponential backoff policy.)
  • Work Chaining (or complex related work, chain individual work tasks together using a fluent, natural, interface that allows you to control which pieces run sequentially and which run in parallel.) Worker(ApplicationContext, WorkerParameters) (Work is defined using the Worker class. The doWork() method is run synchronously on a background thread provided by WorkManager. To create some work for WorkManager to run, extend the Worker class and override the doWork() method.) WorkRequest (The base class for specifying parameters for work that should be enqueued in WorkManager. There are two concrete implementations of this class: OneTimeWorkRequest and PeriodicWorkRequest.)

Api updates

  • 5.0 ART, Notifications (Material design style, Sound and vibration, Lock screen visibility, Media playback, Heads-up notification)
  • 6.0 Runtime Permissions, Doze and App Standby
  • 8.0 Picture-in-Picture mode, Fonts in XML, Autosizing TextView, Multi-display support
  • 10.0 Dark Theme, Gesture navigation