App Dev

Cards (28)

  • Android's thread model has two rules:
    • Do not block the UI thread
    • Do UI work only on the UI thread
  • A worker thread is any thread which is not the main or UI thread
  • AsyncTask allows you to perform background operations on a worker thread and publish results on the UI thread without needing to directly manipulate threads or handlers
  • AsyncTask goes through four steps when executed:
    1. onPreExecute() is invoked on the UI thread before the task is executed
    2. doInBackground(Params...) is invoked on the background thread immediately after onPreExecute() finishes
    3. onProgressUpdate(Progress...) runs on the UI thread after publishProgress(Progress...) is invoked
    4. onPostExecute(Result) runs on the UI thread after the background computation has finished
  • Starting a loader:
    • Use initLoader() to initialize a loader and make it active
  • Restarting a loader:
    • Use the restartLoader() method and pass in the ID of the loader you want to restart. This forces another data load with new input data
  • Network transactions are inherently risky because they involve transmitting data that could be private to the user
  • There are two types of broadcasts:
    1. System broadcasts are delivered by the system
    2. Custom broadcasts are delivered by your app
  • Broadcast receivers are app components that can register for system events or app events
  • Android services are useful for:
    • Performing long-running operations, usually in the background
    • Service lifecycle is simpler than the Activity lifecycle
    • Foreground services are services that the user is aware is running
  • Use alarms to trigger tasks at specific times, whether or not your app is running when the alarms go off
  • Characteristics of an Alarm:
    • Alarms let you send an Intent at set times or intervals
    • Alarms operate outside your app
    • Alarms can help you minimize your app's resource requirements
  • Alarm types:
    • ELAPSED REAL-TIME ALARMS use the time, in milliseconds, since the device was booted
    • REAL-TIME CLOCK (RTC) ALARMS are clock-based alarms that use Coordinated Universal Time (UTC)
  • AlarmManager lets you broadcast an Intent at a scheduled time or after a specific interval
  • To prefetch data means that your app takes a guess at what content or data the user will want next and fetches the data ahead of time
  • Adapter acts as a bridge between an AdapterView and the underlying data for that view
  • Types of Adapter in Android:
    1. BaseAdapter
    2. ArrayAdapter
    3. Custom ArrayAdapter
    4. CursorAdapter
    5. SimpleAdapter
    6. Custom SimpleAdapter
  • ListView shows items in a Horizontal form and displays them in a Vertically-Scrollable collection
  • GridView shows items in a tabular form or a 2-Dimensional view, in rows and columns, and is vertically-scrollable
  • Spinner shows items in a horizontal form and displays a list of values like a dropdown menu when an item is chosen
  • Android provides several options for saving persistent app data:
    1. Shared preferences
    2. Internal storage
    3. External storage
    4. SQLite databases
    5. Room persistence library
    6. Cloud backup
    7. Firebase realtime database
    8. Custom data store
  • Files in Android are stored in a file system similar to disk-based file systems on other platforms like Linux
  • Internal storage is always available, and you don't need any permissions to save files on it
  • External storage is not always available, and you need to request the WRITE_EXTERNAL_STORAGE permission to write to it
  • There are public and private directories specific to your app in external storage
  • Firebase offers a Realtime Database for data management, where data is stored as JSON and synchronized in real-time to every connected client
  • JobScheduler allows you to schedule a task around specific conditions rather than a specific time as with AlarmManager
  • JobScheduler has three components:
    1. JobInfo
    2. JobService
    3. JobScheduler