Kotlin Flashcards
Activity vs Fragments
Activity is the main screen of the application the user interacts with. Fragments are the pieces that make up the Activity and can be thought of as sub-Activities. Fragments can be moved around and manipulated to design many activities.
did good
Describe the Lifecycle of Activities
Process of user starting, using and exiting application. Six callbacks: onCreate(), onStart(), onResume(), onPause(), onStop(), onDestroy(). The system invokes the callbacks when an activity enters a new state (starts to do something new).
Need examples for each callback.
onCreate(): where I initialize any UI elements or data objects.
What is the activity content?
Activity content is what is in the Activity. It’s what defines the applications UI using #setContentView() and initialized by #onCreate()
What is an interface?
Interfaces in Kotlin have declarations of abstract methods as well as method implementations. Unlike abstract classes, interfaces cannot store state (can’t store data/ have variables). An interface cannot be instantiated (you can’t create an object/ you can’t create an instance of an object). Interfaces have abstract methods that can be called by other classes or its sub-classes.
An interfaces content can be called by another class or function later. Using override, can change the interface contents values to suit different situations.
Need an example
An interface can hold a variable named “avg test scores” of type int without any content. Then a class named “7th grade English” can call the interface and assign a value. Another class named “8th grade English” can call the interface but assign a different value.
What is the intent? Explicit vs Implicit
What is intent definition?
Intent is a request made to part of an app for an operation or action to be performed. Usually for launching activities.
“Passive data structure holding an abstract description of an action to be performed.” - too wordy
Explicit intent is when the app performs an action that calls upon information provided locally. Implicit intent gives directions to the app’s next destination without providing the actual destination, ex. an app leading to a 3rd party website.
What is your process to create an SDK? How does this differ from a standard application?
SDK stands for software development kit and exists to make it easier to develop software. My process to create an SDK is to understand the API the SDK will work with. The SDK commonly includes a compiler, code samples, code libraries, testing and analytics tools, instructions, and debugging tips. Want to make sure the SDK is tested, updated regularly, and published on the correct platform. The difference between an SDK and a standard application is an SDK is just some code to help the developer get started. The application is closer to a finished product and can use an SDK to be made.
did good
How do you handle multi-threading?
Multi-threading is when an app needs to multi-task and is how background tasks work.
What libraries would I use? watch a tutorial take notes and send to kevin
How do you handle frequent crashing in an application?
It depends on the situation. Check the logs (logcat) and add checkpoints (inside of the terminal that tells you errors, when you add checkpoints the simulator will stop at those points). Basic tips include identifying the root cause of the crash and trying to reproduce the error in a separate space. Can detect the problem using Android Vitals and find out where it happens using a stack trace.
How do you handle API calls? (Volley)
An API call is a message sent to a server asking an API to provide a service or information. Volley is an HTTP library that makes networking for Android apps easier and faster and is used for caching and making a network request in Android applications. To use volley for your app to communicate with an API, add the volley dependency to app module-level build.gradle file. Then use the getData method to receive information from an API.
did good
Serializable vs Parcelable?
Serializable is a standard Java interface and is easy to use but slower. It can be implemented and include override methods. Reflection is used in the process which causes it to be slow. Lots of temporary objects are created.
Parcelable is much faster than serializable because it’s explicit about the serialization process rather than using reflection to infer. The code has likely been heavily optimized to support parcelable.
did good
these are (kinda special pre-built) interfaces that help translate to JSON to Kotlin in the compiler. turning JSON objects into Kotlin objects.
should probably google when to use serializable vs parcelable
if going to using other technolgies already written in JAVA with legacy code, might be handcuffed to serializable. A lot of code is stuck in the past, so have to keep using old interfaces and old code.
What is a Data Class?
It’s a class that holds data; ex: a set of attributes and values over data class in other languages.
Focus more on this to show experience
we could use a data class to list out a model or client requirements that will usually be previously discussed with the team to go ahead and implement them later.
Need examples:
guitar model data class just describes attributes of the guitar (website for selling guitars)
guitar model interface can have functions, like play guitar
(app that plays instruments)
In a data class you can assign a default value and can’t use functions. In an interface, you can use both variables and functions, but it’s abstract so no implementation is allowed.
Data class can assign a default value.
Interface cannot assign a default value.
Singleton
A singleton is an object that is created only once but can be used everywhere. Using the Singleton Pattern, the singleton class can only be instantiated in one instance.
need example: (might be bad example)
Suppose you have an app, and users can Login to it after undergoing user authentication, so if at the same time two user with same name and password tries to Login to the account, the app should not permit as due to concern of security issues. So singleton objects help us here to create only one instance of the object, i.e user here so that multiple logins can’t be possible.
another example:
app with a lot of user input and persistent memory then might want to make a memory manager singleton that’ll take care of any inputs and outputs in real time.
shopping cart. when i add an item to shopping cart it changes, but it’s always using the same shopping cart.
did good
Lazy vs lateinit
If you don’t want to initialize a class property inside the constructor or in the top of the class body, can use lazy or lateinit. It’s essentially a promise to the compiler that the value will be initialized in the future. Lazy is used for val and lateinit is used for var.
did good
Need example
Lateinit variable is used when we want to pass it’s value through a paramater in the constructor. That’s why we call it a promise to the compiler when we initialize it.
A lazy variable is reserved for memory or processor heavy operations for efficiency’s sake. By default, static objects are lazy. Static objects can be accessed anywhere in code, but pay for it in performance (not energy efficient).
Persistent memory
Persistent memory is when information is saved locally (on the device the app is installed on). Ex: a user saving their progress in a game requires persistent memory. SharedPreferences allows developers to store basic data types via key-value pairs and its stored on the device for as long as the app is installed.
SharedPreferences
did good
Notification manager and push notifications
Use NotificationCompat APIs from the Android support library and then write the code for the windows.
To stay in the native environment I would use firebase to distribute notifications. Firebase is a server side service owned by google. Any info I want to host is located there. Can use to authenticate login ex: