Core Android Flashcards

1
Q

What is Context? How is it used?

A

The context can be simply explained as where we are currently at or describing
it can be used to get information regarding the activity and application
it can also be used to get access to resources, databases, and shared preferences

Application Context
used when you need a context that will outlive any other context.

Activity Context
represents the activity and lifecycle useful for UI operations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are Activity and its lifecycle?

A

an activity is the entry point for an app and provides a window for the UI.

  • onCreate
    • Called when activity is first created.
  • onStart
    • Called when activity is becoming visible to the user.
  • onResume
    • Called when activity will start interacting with the user.
  • onPause
    • Called when activity is not visible to the user.
  • onStop
    • Called when activity is no longer visible to the user.
  • onRestart
    • Called after your activity is stopped, prior to starting.
  • onDestroy
    • Called before the activity is destroyed.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

why do we need to call setContentView() in onCreate() of activity class?

A

onCreate is called only once when the activity starts. so calling the setContentView inflates the UI

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is onSavedInstanceState() and onRestoreInstanceState()

A

onSaved will be called before pausing the activity

onRestore will be used to recover the saved state when the activity is recreated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is a fragment and its lifecycle

A

a fragment is a sub-activity that has its own layout
It added from an activity
has its own behavior and lifecycle but is closely related to the host activity lifecycle
fragment will be used if you need to have multiple views displayed beside each other or reuse the display

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what are launch modes

A

they launch activities with a certain set of instructions that can help with the task

standard - creates a new instance of the activity everytime

singletop - if the activity is already on top of the stack a new instance will not be created otherwise it will create a new activity

single task- only creates one instance of the activity if the activity is already in the stack then it will destroy the activities in front of it

single instance- will create a new stack for the activity so whenever there is a new instance of that activity it will get it from that stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is the differnce between FragmentPageAdapter vs FragmentStatePagerAdaper

A

FragmentPagerAdapter- Each fragment visited by the user will be stored in the memory but the view will be destroyed when the page is revisited then the view will be created not the instance of the fragment.

FragmentStatePagerAdapter- the fragment instance will be destroyed when it’s not visible to the user, except the saved state of the fragment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between adding/ replacing fragment in backstack?

A

add to back stack means the transaction will be remembered and will be reversed when pupped off the stack
add will add a fragment to the activity state

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

why is it recommended to use only the default constructor to create a fragment

A

when android has to restore a fragment it will use the default constructor like when an orientation change occurs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

switch vs when in kotlin

A

the when statement in kotlin is more powerful then the switch statement.
-you can use more then one choice in a case
-you can add conditions to cases
-you can pass any type
finally when doesn’t need an else statement and will break on the first case it finds

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is inheritance

A

inherit properties from other classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

superclass vs subclass

A

superclass is is a parent class or base class so the subclass will inherit from the base class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

polymorphism

A

multiple definitions can be given to a single interface

used when different subclasses need need different methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

polymorphism

A

multiple definitions can be given to a single interface

used when different subclasses need different methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

overloading vs overriding

A
overloading has two or more methods have the same name but different parameters 
overriding a child class redefines a methods in the base class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

how to communicate between two fragments

A

you can use a shared ViewModel
observing livedata in one fragment and changing live data in another
or by interfaces
creating an interface in one fragment implement that interface in the activity and then call a method in the second fragment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

View.GONE vs View.INVISIBLE

A

View.GONE will make it so the view is removed from the layout
View.INVISIBLE will make it so the view still takes up space in the layout but you can’t see the view

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Constraint layout

A

It is a flexible layout that can adapt to different screen sizes. they can avoid the nested layouts which leads to less complex layouts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

List View vs RecyclerView

A

a recycler view is an improved list view.

  • recycler view reuses cells while scrolling up and down
  • decouples list from its container
  • animates common list actions
20
Q

What is Intent

A

an intent is a messaging object that can be used to request an action from another app component.

implicit - all you need to do is specify the action that will be performed by the intent and the android system will search all available components that can perform that action

explicit - are used to communicate with a particular component of the same application.

you can use intents to start activities
starting a service
delivering a broadcast

21
Q

What are Intent filters

A

they are expressions that are used to specify the type of components or actions that can be received by the application

22
Q

broadcast receiver

A

listens for broadcasts and respond to broadcast messages from other applications or from the system

23
Q

broadcasts

A

broadcasts sends a message out so any broadcast receiver that is listening

there are 3 ways to send a broadcast

24
Q

what is a service

A

an android component that preforms long running tasks in the background that don’t need to provide UI
3 types of services

foreground- is a service that lets the user know what is going on. ie music player

background- the user wont know what is going on like when compressing an image when you send it

bound- you can bind a service to an activity so even if you leave the app the service can still run and when you come back you can take back control of the service

25
Q

Content Providers

A

helps applications manage access to data stored by itself, other apps, and share data with other apps. they provide tools for data security.
they are the standard interface that connects data between processes.
you can configure a content provider to allow other applications to securely access and modify your app’s data.
if you don’t plan to share data you can still use content providers to abstract your data

some use cases would be implementing a custom search suggestion in your application using the searchRecentSuggestionsProvider

exposing your data to widgets
to access a content provider you can use the contentResolver

26
Q

what is an ANR

A

application not responding happens when no response to an input event within 5 seconds or a broadcast receiver hasn’t finished executing within 10 seconds

27
Q

intent service

A

an intent service is a service that is started by a intent. this intent is received on the main thread and then a worker thread is started for the service. tasks are handled on a FIFO bases

28
Q

JobScheuler

A

lets your app schedule jobs that won’t be terminated due to the android system.
these jobs can be batched so that the system can use fewer resources.
some good times to use a job scheduler are when
tasks are not critical or user-facing,
tasks that require network access
tasks that should be running on a regular basis

29
Q

shared preferences and when to use

A

is a way to store data in the key-value pair

ex for a one time pop up welcome screen

30
Q

internal storage and when to use

A

a way to save data the android system will provide some private internal storage only your app can access. when the app is uninstalled the data will be deleted.

you want to use the internal storage when you have private data for your app if the data is being shared it might not be a good idea for internal storage

31
Q

external storage and when to use

A

is a way to store data but this data will be accessible to everyone.
you should use external storage when storing a large file or you have shared data. it can also be used if you want some data to persist after deleting the app.

32
Q

database and when to use

A

is an organized collection of data stored for future reference.
if you have data that you want to structurally store

33
Q

shared storage

A

there is internal storage for apps and then the rest of the storage is shared storage. any app that has storage permissions can access this storage.

when you have data that can be shared

34
Q

crashes

A

android vitals can alert you of your apps performance if it has exsesive crashing.
first you need to identify the place where the crash is happening. you can use stack trace to help out with this.
or you should reproduce the the crash locally either by testing the app or reaching out to affected users

a stack trace will show you the type of expectation thrown and the section of code where the exception is thrown.

reproducing the crash in a development environment can be hard to reproduce because the development environment can have more resources. to counteract this use the type of exception to determine what could be the resource that is scarce and limit it.

35
Q

Live data

A

LiveData is a data holder that follows the observer design pattern and is lifecycle aware. if an observer is not in an active lifecycle state then it won’t be updated.

the observer will subscribe to the observable and when the observable is updated the observer will be notified.

36
Q

Work Manager

A

work manager is the recommended way to schedule background tasks. work manager makes sure the scheduled task will run even if the app or device restarts.

37
Q

ViewModel

A

is used to handle configuration changes - objects are kept when an activity is recreated

lifecycle awareness-
data sharing- between fragments is easy
coroutines support

38
Q

unit tests

A

a way to evaluate the app’s logic without running tests on a device

39
Q

bundles

A

is a way to pass data around between activities

40
Q

Git

A

prevents loss of work.
keeps track of the history of changes
you can work independently on a separate branch
you should commit often
make sure you working with the latest version to avoid merge conflicts
make detailed commits
use branches

41
Q

view binding

A

allows you to bind ui components in your layouts to data sources in your app.
instead of using find view by id you assign data directly to the widget in the layout file.

42
Q

okhttp

A

is a very handy tool we can use for introceptors

43
Q

constructor vs method

A
constructor has the same name as the class and methods can be anything
there is no return type on the constructor
a constructor is called when an object is created
44
Q

abstract class vs interface

A

an abstract class is a class that contains both concrete and abstract methods. an abstract method must be implemented by an abstract subclass. an abstract class can not be instantiated but have to be extended to be used

the interface is a blueprint of a class. contains empty methods that will be used by all subclasses. the subclasses will implement those methods.

45
Q

access modifiers

A
private- visible inside the class only
default- allows access from inside the same package
protected - same as private but visible to subclasses
public- any client who sees the declaring class sees it