Android Experienced Interview Q I

1. What is a Service?

A service does not create its own thread and does not run in a separate process unless you specify. You should run any blocking operations on a separate thread within the service to avoid Application Not Responding (ANR) errors.

2. What is a Broadcast Receiver?

Types of receivers.

3. What is the memory leak in Android?

Please refer to this link, very well explained.

4. What are the possible states in which a process is based?

5. What are the states in an activity?

There are four states in an activity. These include the following.

  1. Active state: The activity is in the foreground
  2. Paused state: The activity is in the background and visible
  3. Stopped state: The activity is in the background but not visible, even hidden or obscuring other activities
  4. Destroyed state: The activity is completely terminated or killed/removed

6. Explain the different launch modes in Android (most asked question)

  1. Standard:

for Example — If the Activity stack is X⇾ Y⇾ Z and if I want to launch Y Again then the new stack is X⇾ Y⇾ Z⇾ Y

2. Single Top:

if the Activity stack is X⇾ Y⇾ Z and I want to launch Y again because the recent stack is not Y it's Z, so the new Flow will be X⇾ Y⇾ Z⇾ Y

if the Activity stack is X⇾ Y⇾ Z and I want to launch Z again because the recent stack is Z, so the new Flow will be X⇾ Y⇾ Z (instead of creating a new flow, it will send the Intent to onNewIntent()).

3. Single task:

4. Single Instance:

6. If Apps are crashing frequently, what approach you will take to troubleshoot the problem?

8. How many ways we can define Android Permission?

  1. Normal Permissions — The system will automatically provide authorization to your app during the installation process.
  2. Signature Authorization — The app requesting permission must be signed with the same signature as the app defining the needed permission
  3. Dangerous Permission — The app requesting permission is directly related to users' privacy. If the user refuses the permission, your application will be unable to utilize that permission.

9. Difference between MVP and MVVM architecture?

10. Details about RX Java, Live Data and Coroutines-

Why Rx Java, live data or coroutine?

Consider the scenario: we are doing some background work which needs to run as a long-running task if we do this on the main thread then maybe after sometimes our app will through ANR or crash, so we will do it with the async task (already deprecated) the other approach we have right now is RX Java, Coroutines, flows etc.

RX Java :

RxJava is a JVM library that uses observable sequences to perform asynchronous and event-based programming

RxJava, on the other hand, is designed primarily for Java projects. RxAndroid is required to use RxJava in Android.

It simplifies multithreading in our project. It assists us in determining which thread we want to run the task on

Live Data

Live Data is a reactive solution for delivering events to UI in Android. It is aware of the life cycle of the owner and because of that, it is simple to use. You don’t need to save any subscription-like object to unsubscribe when needed. However, its simplicity carries some drawbacks — it only works on the Main Thread. Another drawback is that there are no operators or ways of combining results from different Live Data streams.

Coroutines

A coroutine is compatible with Kotlin language, which works for asynchronous code. It was developed by JetBrains.

A coroutine is a lightweight thread. Kotlin compiler automatically generates state machines from the code, so the code will behave as normal synchronous code.

Overall view of all three-

10. How to reduce APK size?

Please follow this link

11. Dependency Injection in Android

Why Dependency Injection- if we have a larger code base, and we are going to create an object which depends on many other objects, then what will be the complex scenario? If we don't use it in any class, we need to write a bunch of extra code. This time we might need something external to handle this

in Android, we have Dagger2, Hilt. Koin dependency injection to make our code easy to understand.

The benefit of Dependency Injection-

12. Design Pattern in Android?

Please follow the link

13. Why Manifest.xml?

Every Android App must have Manifest.xml. The manifest File is defined as the Essential operations in the app.

Here is the main list of data which we require to register in Manifest for the successful App run

1. App component — Activity, Services, Broadcast receiver, content provider. These all the Component may have some additional attribute to register, for example — Intent filters that describe how the component can be started

2. Permissions — It is used to create permissions to restrict access to protected parts of the system or other apps.

3. Application — Manifest can contain only one application node. In the application Tag, we can set some more attributes like title, icon and theme.

The Application node is to act as a container for the Activity, service, content provider and broadcast receiver.

4. Uses-Feature — It is used to specify which hardware features your application requires. This will prevent our application from being installed on a device that does not include a required piece of hardware.

5. supports-screens — It is used to describe the screen support for our application

<supports-screens
android:smallScreens=”false”
android:normalScreens=”true”
android:largeScreens=”true”
android:xlargeScreens=”true”/>

14. What is the difference between service and thread?

15. how to secure the Android Applications?

When we communicate between two apps or websites, that time we need to take care of the stability of the apps and protect the data that we are sending or receiving from other apps. According to the Android Developer site, we should take care this way-

Use implicit intents and non-exported content providers-
Apply for signature-based permissions-
Disallow access to your app’s content providers-
Ask for credentials before showing sensitive information-
Apply network security measures-
Add a network security configuration-
Create your own trust manager-
Use WebView objects carefully-
Use HTML message channels-
Provide the right permissions-
Store data safely-
Store private data within internal storage-
Store data in external storage based on the use case-
Store only non-sensitive data in cache files-
Use SharedPreferences in private mode-
Keep services and dependencies up-to-date-

The best explanation is in this link for the network security config.

16. What is the difference between Handler vs Async Task vs Thread?

17. What is the difference between a Bundle and an Intent?

18. Provide some tips to reduce battery usage in an android application

The battery optimisation of Apps depends on many factors as-

  1. Reduce network calls if we can for some of the scenarios — Cache your data and retrieve it from the cache when required next time.
  2. Batch operations- we can batch the network calls if possible so that we can prevent the device from waking every time.
  3. Check All background process
  4. Use GPS carefully- will use GPS when required.
  5. Use Work Manager- WorkManager incorporates the features of its predecessors in a modern, consistent API that works back to API level 14 while also being conscious of battery life.
  6. Avoid Wake locks- Using a wake lock to keep a phone’s screen or CPU on is one of the most common ways an app will drain a battery.

19. What’s the difference between a file, a class and an activity in android?

20. What is Sticky Intent vs Pending Intent?

Sticky Intent — When the Android System send the sticky Broadcast for any changes in battery status, the intent is available after the broadcast receiver has completed its work. after some time we can retrieve the Data from the intent regarding the battery status by using registerReceiver(method)

Pending Intent — When you want to open some application components like Activity, Service or BroadcastReceiver after some specified time interval you have to send PendingIntent in this case.

It's something we are giving permission to another app to run the app after some time. for example notification(if we want to open some activity on click on notification here we can use pending intent)

to be continued…

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prachi Mishra

I am an Android Developer. Working for BMW group. In my development path if I find something interesting I like to share with you guys. Happy coding…