Top 15 Common Android Interview Questions for Experienced Android Developers
Hello forks how are you doing, today was thinking about aritcle title then suddenly got idea why shouldn't I share common question that are being asked in interview mostly? So forks without wasting time lets start…
1. What is Work Manager?
Work Manager is an Android Jetpack library that provides an API for scheduling background tasks. It allows you to perform tasks that need to run in the background, even if the app is closed or the device restarts. Work Manager intelligently chooses the appropriate execution strategy based on factors like device conditions and power constraints.
Example:
val workRequest = PeriodicWorkRequest.Builder(MyWorker::class.java, 1, TimeUnit.DAYS).build()
WorkManager.getInstance(context).enqueue(workRequest)
2. Differentiate VAL vs VAR vs Const val:
- ‘val’ is used to declare a read-only (immutable) variable, meaning its value cannot be changed once assigned.
- ‘var’ is used to declare a mutable variable, allowing its value to be reassigned.
- ‘const val’ is used to declare a compile-time constant value, which cannot be changed and is evaluated at compile-time.
3. What are Launch Modes of Android activity?
Launch modes define how a new instance of an activity should be launched in the task stack. There are four launch modes:
- Standard: Each time an activity is launched, a new instance is created and placed on top of the stack.
- SingleTop: If the activity is already at the top of the stack, it won’t be recreated; otherwise, a new instance is created.
- SingleTask: Only one instance of the activity can exist in the stack. If an instance already exists, the system brings it to the foreground instead of creating a new one.
- SingleInstance: The activity is launched into a new task and a separate task stack. Only one instance of the activity can exist across all tasks.
4. What is difference between Service and IntentService:
- Service: A Service is a component that runs in the background without a user interface. It can perform long-running operations, but it runs on the main thread by default, so you need to handle threading manually.
- IntentService: IntentService is a subclass of Service that provides a default implementation for handling asynchronous requests using a worker thread. It automatically stops itself when the work is complete.
5. What is difference between lateinit vs lazy:
- ‘lateinit’ is used for declaring non-nullable properties that will be initialized later before being used. It allows you to delay the initialization of a variable.
- ‘lazy’ is a function that takes a lambda and returns an instance of Lazy<T>. It is used for declaring properties that are initialized lazily when they are first accessed.
Example:
lateinit var name: String
val fullName: String by lazy { firstName + " " + lastName }
6.Describe difference betweenLiveData vs MutableLiveData:
- LiveData is an observable data holder class that is part of the Android Architecture Components. It is lifecycle-aware, meaning it only updates the observers when they are active.
- MutableLiveData is a subclass of LiveData that allows you to modify its value. It is commonly used when you need to update the value of LiveData from within a ViewModel.
Example:
val data: LiveData<String> = MutableLiveData<String>()
// Setting a new value using MutableLiveData
(data as MutableLiveData<String>).value = "New Value"
7. setValue vs postValue:
- ‘setValue’ is a method of MutableLiveData that sets the value of the LiveData synchronously. It should only be called from the main thread.
- ‘postValue’ is a method of MutableLiveData that sets the value of the LiveData asynchronously. It can be called from any thread.
8. What is the difference between compileSdkVersion and targetSdkVersion?
- ‘compileSdkVersion’ is the version of the Android SDK against which the app is compiled. It determines which APIs and features are available during the build process.
- ‘targetSdkVersion’ is the version of the Android framework that the app is targeting. It indicates the highest API level that the app has been tested against and guarantees the app’s compatibility with that version.
9. What is a Repository in MVVM?
In the MVVM (Model-View-ViewModel) architecture pattern, a repository acts as a mediator between the ViewModel and the data sources. It abstracts the data access, providing a clean API for the ViewModel to retrieve and manipulate data. The repository can fetch data from a remote server, local database, or any other data source.
10. HashMap vs HashTable:
- Both HashMap and HashTable are data structures used to store key-value pairs.
- HashMap is not synchronized and allows null keys and values. It is generally preferred over HashTable in non-threaded environments.
- HashTable is synchronized and does not allow null keys or values. It is thread-safe but has a performance overhead.
11. What is SSL Pinning:
SSL Pinning is a security mechanism used in mobile apps to ensure that the app only communicates with a trusted server. It involves associating the server’s SSL certificate or public key with the app in a secure manner. This prevents attackers from intercepting or tampering with the network traffic by presenting fake certificates.
12. What is Dependency Injection:
Dependency Injection is a design pattern that enables loose coupling between components in an application. It allows you to provide dependencies to a class from external sources, rather than the class creating or managing the dependencies itself. This promotes modular and testable code.
13. Benifits of using Android Studio Profiler:
Android Studio Profiler is a powerful tool that helps developers analyze the performance and behavior of their Android apps. It provides real-time monitoring of CPU
, memory, network, and other resource usage. The profiler can identify performance bottlenecks, memory leaks, and help optimize app performance.
14. Diffrenciate Final, finally & Finalize:
- ‘final’ is a keyword used in Java/Kotlin to indicate that a variable, method, or class cannot be further modified or extended.
- ‘finally’ is a block of code that is executed regardless of whether an exception is thrown or not. It is typically used to release resources or perform cleanup operations.
- ‘finalize’ is a method in Java that is called by the garbage collector before an object is garbage collected. It allows the object to perform any necessary cleanup actions before being destroyed.
15. Activity and Fragment Lifecycle:
Both Activity and Fragment have a lifecycle consisting of various stages such as onCreate, onStart, onResume, onPause, onStop, and onDestroy. These lifecycle methods allow you to manage the initialization, execution, and termination of activities and fragments. Understanding the lifecycle is crucial for managing state, handling configuration changes, and ensuring smooth user experiences. Please refer my Article for more details.
Conclusion:
These 15 Android interview questions cover a wide range of topics that experienced Android developers should be familiar with. By understanding these concepts and their nuances, along with the provided examples, you will be better prepared for your next Android interview.
Remember to practice implementing these concepts in your code and stay updated with the latest advancements in Android development. Good luck with your interviews!
If you found article useful then please start following me. You can also find me on LinkedIn and GitHub.
You can find my more article on GFG portal and start following me there.