Android Architecture & Design Interview Questions & Answers

Neha Saini
7 min readMar 30, 2024

--

Hi Everyone,

In this post, I will outline some key questions commonly asked during Architecture & Design interviews for Android developers.

1. What occurs when the “Run” button is clicked in Android Studio?

Answer: As soon as you click on the run button below process starts in the background for the Gradle system:

  • Build Process: Android Studio triggers the Gradle build process for your project. Gradle is responsible for compiling your Java/Kotlin code, packaging resources, and generating the APK (Android Package) file.
  • Resource Compilation: Resources such as layouts, drawables, and strings are compiled and processed to be included in the APK.
  • Manifest Merging: If your project includes libraries or modules, Android Studio merges their manifests with your app’s manifest to create the final manifest file.
  • Code Inspection: Android Studio performs code inspection to check for errors, warnings, or potential issues in your code.
  • Lint Checking: Android’s Lint tool checks your code and resources for potential performance, usability, and security issues.
  • Instant Run (Optional): If Instant Run is enabled, Android Studio attempts to push only the changed code and resources to the running app on the device or emulator, speeding up the build and deployment process.
  • Deployment: Once the build is successful, Android Studio deploys the APK to the selected device or emulator.
  • Launch: Finally, Android Studio launches the app on the device or emulator for testing.

2. How do APK and app bundles differ in terms of their configurations and contents?

Answer: An APK (Android Application Package) and an Android App Bundle (AAB) are both ways to package and distribute Android apps, but they have some key differences in terms of configuration and what they include:

APK (Android Application Package):

  • Configuration: The APK is a single, compiled file that contains all the resources and code necessary to run an Android application on a device. It includes all the compiled code (DEX files), resources (such as images and XML files), and the manifest file that describes the app’s structure and requirements.
  • Contents: The APK includes resources and code for all device configurations (such as different screen densities or CPU architectures). This can result in larger APK sizes, especially when including resources for multiple device configurations.

Android App Bundle (AAB):

  • Configuration: The Android App Bundle is a publishing format that includes compiled code and resources but does not contain everything needed to run the app on a device. Instead, it contains the app’s compiled code (DEX files), resources, and a manifest file, as well as a set of split APKs for different device configurations.
  • Contents: The AAB does not include resources for all device configurations in a single package. Instead, it includes split APKs (also known as “splits”) that contain resources optimized for specific device configurations. When a user installs an app from the Play Store, the Play Store dynamically generates an APK that includes only the resources and code necessary for the user’s device.

3. How can Kotlin code be invoked from within a Java service class?

Answer: To call Kotlin code from inside a Java service class, you can use Kotlin’s interoperability features. Here’s an example

class MyKotlinClass {
fun getData(): Flow<String> {
return flow {
for (i in 1..3) {
delay(1000)
emit("Data $i")
}
}
}
}
public class MyJavaService {

public void fetchData() {
MyKotlinClass myKotlinClass = new MyKotlinClass();

Flow<String> flow = myKotlinClass.getData();
CoroutineScope scope = new CoroutineScope(Dispatchers.Default);

scope.launch(() -> {
flow.collect(System.out::println);
});
}
}

we create an instance of MyKotlinClass and call its getData() function to obtain a Flow<String>. We then use CoroutineScope and launch to collect items from the flow and print them. Make sure to handle the coroutine scope properly to avoid memory leaks.

KotlinInterop is a feature of Kotlin that allows seamless interoperability between Kotlin and Java code. It ensures that Kotlin code can be called from Java and vice versa without any major hurdles.

For example, when you define a Kotlin function or class and want to use it in Java, the Kotlin compiler generates a corresponding Java-accessible class or method, making it possible to use Kotlin constructs in Java code. This is particularly useful when you’re working in a mixed-language environment or transitioning from Java to Kotlin gradually, as it allows you to leverage existing Java code while taking advantage of Kotlin’s features.

4. What occurs when a main app integrates modules from two different apps, where the modules from app 1 use Gradle version 8.2 and modules from app 2 use Gradle version 8.5?

Answer: When you include modules with different Gradle versions in your main app, Gradle will use the highest version specified in any of the included modules. This means that if module 1 uses Gradle version 8.2 and module 2 uses Gradle version 8.5, the main app will use Gradle version 8.5.

However, using different Gradle versions across modules can lead to compatibility issues or unexpected behavior, especially if the versions are significantly different. It’s generally recommended to keep the Gradle versions consistent across all modules to avoid such problems. If you encounter issues, you may need to update the Gradle version in one of the modules to match the other.

5. What is the difference between R8 & D8 tools?

Answer: R8 and D8 are both tools used in the Android build process for code optimization and transformation, but they serve different purposes:

D8 (Dexer 8):

  • D8 is the Dexer for Android, responsible for converting Java bytecode into Dalvik bytecode (DEX format) that can run on Android devices.
  • D8 is used in the Android build process to transform Java bytecode (.class files) into DEX files, which are then packaged into the final APK.
  • D8 performs various optimizations, such as dead code elimination, method inlining, and bytecode simplification, to improve the performance and size of the resulting DEX files.

R8 (Shrinking, Optimization, and Obfuscation Tool):

  • R8 is a code shrinker, optimizer, and obfuscator for Android apps. It replaces ProGuard as the default tool for these tasks in newer versions of the Android Gradle Plugin.
  • R8 analyzes the code and resources of your app and removes unused classes, fields, and methods to reduce the size of the APK.
  • R8 also performs optimizations similar to D8, such as inlining and simplification, to improve the runtime performance of the app.
  • Additionally, R8 can obfuscate the code by renaming classes, methods, and fields to make it harder for reverse engineering.

6. What is the difference between KMM & KMP?

Answer: KMM (Kotlin Multiplatform Mobile) and KMP (Kotlin Multiplatform) are both Kotlin-based technologies that allow you to share code between different platforms. However, they are used in slightly different contexts:

KMM Internal working

Kotlin Multiplatform Mobile (KMM):

  • Focus: KMM is specifically designed for sharing code between Android and iOS apps, allowing you to write common business logic, data processing, and networking code that can be used on both platforms.
  • Usage: KMM is used for mobile app development, where you want to reduce duplication of code and ensure consistency across Android and iOS apps.
  • Tools: KMM provides tools and libraries specifically tailored for mobile development, such as integration with Android Studio and Xcode.

Kotlin Multiplatform (KMP):

  • Focus: KMP is a more general-purpose framework for sharing code across multiple platforms, including desktop, web, server-side, and IoT.
  • Usage: KMP can be used in a wide range of applications where you want to write shared code once and use it across different platforms.
  • Tools: KMP provides a set of tools and libraries that enable you to write platform-agnostic code, but it may not have the same level of integration with mobile development tools as KMM.

7. How do independent modules communicate with each other in a multimodular app?

Answer: Modules rarely exist in total separation and often rely on other modules and communicate with them. It’s important to keep the coupling low even when modules work together and exchange information frequently. Sometimes direct communication between two modules is either not desirable as in the case of architecture constraints. It may also be impossible, such as with cyclic dependencies.

To overcome this problem you can have a third module mediating between two other modules. The mediator module can listen for messages from both of the modules and forward them as needed. In the image above, the checkout feature needs to know which book to purchase even though the event originated in a separate screen that is part of a different feature. In this case, the mediator is the module that owns the navigation graph (usually an app module). In the example, we use navigation to pass the data from the home feature to the checkout feature using the Navigation component.

navController.navigate("checkout/$bookId")

If this post helped you in any way, please consider liking and following me for more informative posts. Your support helps me create more content like this. Thank you for reading!”

Stay Tuned !!!

--

--