Nov.07

Interview: Android – Kotlin

Queston: What are Lambda Expressions and Anonymous Functions?

Lambda expressions and anonymous functions are ‘function literals’, i.e. functions that are not declared, but passed immediately as an expression.

Lambda expression is always surrounded by curly braces, parameter declarations in the full syntactic form go inside curly braces and have optional type annotations, the body goes after an -> sign. If the inferred return type of the lambda is not Unit, the last (or possibly single) expression inside the lambda body is treated as the return value.

Anonymous function looks very much like a regular function declaration, except that its name is omitted. Its body can be either an expression or a block. We can specify return type in anonymous function.


Question: What are Coroutines?

Coroutines are a new way of writing asynchronous, non-blocking codes (and much more). Coroutines are sort of tasks that threads can execute. Threads can stop executing coroutines at some specific “suspension points”, and go do some other work. Also threads can resume executing coroutines later on, or another thread could even take over.


Question: What are CoroutineContext and CoroutineDispatcher?

Coroutines always execute in some context represented by a value of the CoroutineContext type, defined in the Kotlin standard library. CoroutineContext is a set of various elements. The main elements are the job of the coroutine and its dispatcher.

Coroutine context includes a coroutine dispatcher that determines what thread or threads the corresponding coroutine uses for its execution. CoroutineDispatcher can confine coroutine execution to a specific thread, dispatch it to a thread pool, or let it run unconfined.


Question: What are GlobalScope and CoroutineScope?

GlobalScope is used to launch top-level coroutines which are operating on application lifetime and are not cancelled prematurely.

CoroutineScope defines a scope for new coroutines. Coroutine builders are extensions on CoroutineScope and inherit CoroutineContext to automatically propagate context elements and cancellation.


Question: What are Suspend functions?

Suspend functions are at the center of every coroutine. Suspend function is a function that can be paused and resumed at a later time. These functions can execute long running operations and wait to complete without blocking threads.


Question: What are runBlocking and coroutineScope?

runBlocking runs a new coroutine and blocks the current thread interruptibly until its completion. It is not a suspend function and should not be used from a coroutine.

coroutineScope is a suspend fun. When coroutine suspends, coroutineScope function suspends as well.


Question: What are async and launch?

launch starts fire-and-forget coroutine and it returns Job.

async starts coroutine which computes some results and it returns Deferred<*>.


Question: What is Deferred?

Deferred is a kind of analog of future which encapsulates an operation that will be finished at some point in future after it’s initialization.

Android,Kotlin,Interview

Nov.07

Interview: Android – Thread

Question: What is Asynchronous Programming?

Asynchronous programming is a form of parallel programming in which a unit of work runs separately from the main application thread and notifies the calling thread of its completion, failure or progress.


Question: What is Functional Programming?

Functional programming is a process of constructing software by composing pure functions. It avoid concepts of shared state, mutable data and other side-effects. It emphasize on expressions and declarations rather than execution of statements.


Question: What is the difference between AsyncTask and AsyncTaskLoader?

We use AsyncTask class to implement an asynchronous, long-running task on a worker thread. Worker thread is any thread which is not the main thread. AsyncTask uses local context and it destroys itself upon screen orientation changes.

AsyncTaskLoader is equivalent of AsyncTask. But it uses application context. Upon completion, results are automatically delivered to the main thread. Change of screen orientation doesn’t effect AsyncTaskLoader.


Question: What is IntentService?

IntentService is a base class for Services that handle asynchronous requests on demand. IntentService performs certain task in the background and once done, the instance of IntentService terminate itself automatically.


Question: What is RxJava?

RxJava is a Java VM implementation of ReactiveX (Reactive Extensions): a library for composing asynchronous and event-based programs by using observable sequences.

Android,Thread,Interview

Nov.07

Interview: Android – View

Question: What is Fragment?

Fragment represents behavior or portion of user interface in an activity. Fragment must always be hosted in an activity and the fragment’s lifecycle is directly affected by the host activity’s lifecycle. We can combine multiple fragments in a single activity and reuse a fragment in multiple activities.


Question: What are LinearLayout, RelativeLayout and ConstraintLayout?

LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. We can specify the layout direction with the android:orientation attribute.

RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements or in positions relative to the parent.

ConstraintLayout is use to define a layout by assigning constraints for every child view relative to other views. ConstraintLayout is similar to RelativeLayout, but with more power.


Question: What are view Re-usability and Optimization?

RecyclerView is a more advanced and flexible version of ListView. It is a ViewGroup which renders any adapter-based view. It uses recycle or reusable technology for rendering.

We should use custom styles derived from native styles, instead of using native styles directly.

Also we can use <include> tag in layouts to import other layouts. We should avoid creating same layout again and again.


Question: What is Material Design?

Material design is a comprehensive guide for visual, motion, and interaction design across platforms and devices. To use material design in Android apps, we should follow the guidelines defined in the material design specification and use the new components and styles available in the material design support library.

Android,View,Interview

Nov.07

Interview: Android – Core

Question: What is Context?

Context is an abstract class whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.


Question: What is Gradle?

Android Studio uses Gradle, an advanced build toolkit, to automate and manage the build process, while allowing us to define flexible custom build configurations. Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of our application.


Question: What is Activity?

Activity represents a single screen with a user interface. An Android application may contain one or more activities.

Lifecycle of activity:
onCreate() is called when activity is first created.
onStart() is called when activity is becoming visible to the user.
onResume() is called when activity will start interacting with the user.
onPause() is called when activity is not visible to the user.
onStop() is called when activity is no longer visible to the user.
onRestart() is called after your activity is stopped, prior to start.
onDestroy() is called before the activity is destroyed.


Question: What is ARMv7?

ARMv7 is optimized for battery consumption. ARM64 is an evolution of the original ARM architecture which supports 64-bit processing. ARMx86 is not battery friendly but it is more powerful than others.


Question: What are DVM and JVM?

DVM = Dalvik Virtual Machine.
JVM = Java Virtual Machine.

Android uses DVM which runs on low memory. DVM uses own byte code and runs .dex file.


Question: What are App Components?

App Components are the essential building blocks. Each component is an entry point through which the system or a user can enter our app. Some components depend on others.

Each component we create must declare a corresponding XML element in the manifest file.

There are four types of app components:
<activity> for each subclass of Activity.
<service> for each subclass of Service.
<receiver> for each subclass of BroadcastReceiver.
<provider> for each subclass of ContentProvider.

Android,Core,Interview