Cracking Dream Interview Tips-Part 3

Saumya Singh
Coding Blocks
Published in
10 min readDec 5, 2020

--

This blog is continuation of my previous blog in the Interview Preparation series 👩🏻‍💻 🚀.

In Part 3 of Cracking Dream Interview blog series, I will talk about “Must Practice Interview Questions of Android| Top 35”

1. What is an Activity? Which method is implemented by all subclasses of an Activity?

An Activity is the screen representation of an application in Android.

It serves as an entry point for the user’s interaction. Each activity has a layout file where you can place your UI. An application can have different activities. For example, facebook start page where you enter your email/phone and password to login acts as an activity.

Below are the two methods which almost all subclasses of Activity will implement:

  • onCreate(Bundle)
  • onPause()
An activity(screen) of app! whatever we see on the screen in an app is one activity.

2. What is the life cycle of android activity?

User navigates between different screen or app, it goes through different states in their lifecycle. So an activity lifecycle consists of 7 different methods of android.app.Activity class i.e :

onCreate() : In this state, the activity is created.

onStart(): This callback method is called when the activity becomes visible to the user.

onResume(): The activity is in the foreground and the user can interact with it.

onPause(): Activity is partially obscured by another activity. Other activity that’s in the foreground is semi-transparent.

onStop(): The activity is completely hidden and not visible to the user.

onDestroy(): Activity is destroyed and removed from the memory.

activity lifecycle

3. What is An Intent?

Intent is used when the user has to navigate from one activity to another. It is used to move from one activity of the app to a different activity (either of same app or different app)

Types of Intent

Implicit Intent:

  • Implicit intent is when the target component is not defined in the intent and the android system has to evaluate the registered components based on the intent data.
  • It helps in connecting activity of one app with activity of a different app.
  • For example: send email, SMS, dial number or you can use a Uri to specify the data type.

Intent i =new Intent(ACTION_VIEW,Uri.parse("www....");

Moving to an activity of a different app using Implicit Intent

Explicit Intent:

Explicit intent is when an application defines the target component directly in the intent. When we move from one activity to other activity within the same app.

Explicit Intent- Moving to activities within same app

4. What is meant by Services?

  • Service is an Android component that runs in the background and acts independently. It does not provide any user interface.
  • Though the services are running behind the scene, a user can continue their work on different apps. Most of the time, the users are not aware of the services which are running in the background.
  • Once started, a service might continue running for some time, even after the user switches to another application.
  • For example, a service can handle network transactions, play music.

A service is simply a component that can run in the background, even when the user is not interacting with your application, so you should create a service only if that is what you need.

A service is implemented as a subclass of Service class:

Public class MainService extends Service
{ … }

Types of services in android

5. What is the Android SDK?

Android SDK is a software development kit developed by Google for the Android platform. The Android SDK allows you to create Android apps.

The Android SDK is a collection of software development tools and libraries required to develop Android applications.

The tools placed in Android SDk are:

  • Android Emulator
  • DDMS — Dalvik Debug Monitoring Services
  • AAPT — Android Asset Packaging tool
  • ADB — Android debug bridge

6. What are broadcast receivers? How is it implemented?

  • Broadcast Receivers simply respond to broadcast messages from other applications or from the system itself.
  • android BroadcastReceiver doesn’t contain any user interface.
  • To set up a Broadcast Receiver in android application we need to do the following two things.
  1. Creating a BroadcastReceiver
  2. Registering a BroadcastReceiver
Credits- Data Flair

Following are some of the important system wide generated intents.

  1. android.intent.action.BATTERY_LOW : Indicates low battery condition on the device.
  2. android.intent.action.BOOT_COMPLETED : This is broadcast once, after the system has finished booting
  3. android.intent.action.CALL : To perform a call to someone specified by the data

7. Give an example where only onPause() is called but onStop() is not called?

If google assistant or any such pop-up is shown when you are using the app, then activity is not completely gone, but is feebly visible.

In such situations only onPause() is called but onStop() is not called.

8. How will you pass data to sub-activities?

  • We can use Bundles to pass data to sub-activities.
  • Data between activities can also be shared using intents

9. What are fragments?

  • A Fragment is a piece of an application’s user interface or behavior that can be placed in an Activity Interaction with fragments is done through FragmentManager
  • Android Fragment is the part of activity, it is also known as sub-activity. There can be more than one fragment in an activity. Fragments represent multiple screen inside one activity.
  • Each fragment has its own life cycle methods that is affected by activity life cycle because fragments are embedded in activity.
  • The FragmentManager class is responsible to make interaction between fragment objects.
Fragments

10. What are the different kinds of context in Android?

Context defines the current state of an App.

  1. Application Context

2. Activity Context

11. Explain fragment lifecycle.

12. What is difference between listview and recyclerview ?

RecyclerView was created as a ListView improvement. It reuses cells while scrolling up/down.

Comparison
  1. RecyclerView has greater support for LayoutManagement including vertical lists, horizontal lists, grids and staggered grids. ListView only supports vertical lists.
  2. RecyclerView adapters can inform you which items in your data has changed.
  3. RecyclerView has a mandatory use of the ViewHolder pattern providing better performance over ListView that requires customisation to support the ViewHolder pattern.

Performance is dramatically faster, especially if you use RecyclerView.setHasFixedSize.

13. What is Workmanager?

  1. Used for scheduling background tasks.

2. WorkManager is intended for tasks that require a guarantee that the system will run them even if the app exits.

3. WorkManager handles background work that needs to run when various constraints are met, regardless of whether the application process is alive or not.

4. Take care of compatibility issues and best practices for battery and system health for you.

5. It is an android jetpack component.

14. What are content providers in android?

A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the ContentResolver class.

A content provider can use different ways to store its data and the data can be stored in a database, in files, or even over a network.

15. What are the different storages available in android?

Shared Preferences, Internal Storage, External Storage,SQLite Databases and Network Connection

16. How do you find memory leaks in the mobile app on the Android platform?

Android Studio is using Android Device Manager (ADM), this ADM is used to detect the memory leaks in the Android platform.

17. What are sensors?

Android-enabled devices have built-in sensors that measure orientation, motion, and other conditions.

These sensors provide data with high accuracy, which will help to monitor the positioning and movement of the device.

Some of the sensors are hardware-based and few are software-based.

Sensors

18. What is View Group?

The view group is the base class for layouts and views containers.

These layouts include the UI Layouts in Android i.e. LinearLayout, RelativeLayout, FrameLayout etc.

19. What are the Events in Android?

Events are a useful way to collect data about a user’s interaction with interactive components of Applications. Like button presses or screen touch etc. You can capture these events in your program and take appropriate action as per requirements.

20. What is JSON?

JSON stands for JavaScript Object Notation. It is an independent data exchange format and is the best alternative for XML.

21. What is Paging in android?

Paging is a part of the Android Jetpack and is used to load and display small amounts of data from the remote server. By doing so, it reduces the use of network bandwidth.

Some of the advantages of Paging can be:

You will get the content on the page faster.

Working of Paging Library

22. What is Pending Intent?

Pending intent is an intent which will start at some point in the future.

Normal intent starts immediately when it is passed to startActivity(Intent) or StartService(Intent).

23. How two fragments communicate with one another?

  1. Interface (check this link for detailed explanation)
  2. Shared viewmodel

24. What is Rxjava?

Great applications do many tasks asynchronously to give a better user experience.

Rxjava helps us understand how to do asynchronous (multiple threads can access the shared resources or different threads are running at a time) tasks in a better way. Rxjava is not hard it is different.

Rxjava is a library which helps in doing things asynchronously.

For more details, check implementation.

25. When do we extend application class?

If there is some data which you want to use in complete app then put in a class that extends application class.

26. What should be used to create instance of viewmodel?

Viewmodel instance is created using “Viewmodel Provider” (recommended)

otherwise if the instance is created using viewmodel then new object is created every time fragment is recreated.

27. What is Android Jetpack?

ANDROID JETPACK is a collection of components that are required to develop a great Android app.

It provides common infrastructure code so that you can focus on what makes your app unique.

Some android jetpack components are :

  • Room
  • Workmanager
  • MVVM architecture
  • livedata
  • viewmodel

28. What is dependency injection in android?

Dependency injection (DI) is a technique widely used in programming and well suited to Android development.

By following the principles of DI, you lay the groundwork for good app architecture.

Implementing dependency injection provides you with the following advantages:

  • Reusability of code
  • Ease of refactoring
  • Ease of testing

29. What is Proguard Rules?

It detects and removes unused classes, fields, methods, and attributes.

It optimizes bytecode by removing unused instructions.

It renames the remaining classes, fields, and methods using short meaningless names.

30. What is androidx?

AndroidX is a major improvement to the original Android Support Library, which is no longer maintained.

AndroidX stands for Android E X tension Libraries. This simple denotation makes it clearer for an experienced developer what’s behind the term.

Androidx is the package name for all the libraries in jetpack.

31. What is Mutable Live Data ?

Data inside mutable livedata can be assigned multiple times.

32. What is Data Binding?

The Data Binding Library is a support library that allows you to bind UI components in your layouts to data sources in your app using a declarative format rather than programmatically.

The pros of using Android Data Binding:

  • Reduces boilerplate code which in turns brings
  • Less coupling
  • Stronger readability
  • Powerful, easy to implement custom attribute and custom view
  • Even faster than findViewById - The binding does a single pass on the View hierarchy, extracting the Views with IDs. This mechanism can be faster than calling findViewById for several Views.

33. What is a JobScheduler?

The JobScheduler API performs an operation for your application when a set of predefined conditions are met (such as when a device is plugged into a power source or connected to a Wi-Fi network).

This allows your app to perform the given task while being considerate of the device’s battery at the cost of timing control.

34. What Is Localization? How Do You Do It in Android?

Localization is the ability of an app to support multiple languages, time zones, currencies, number formats, etc.

This allows you to distribute your app widely to different countries and populations.

App supporting multi language

Your app can bundle its localization through using Android’s resource directory framework, which specifies items (strings, images, layouts…) for different locales.

35. What are dex files are used for?

A .java file is given to the java compiler (javac) to generate the .class file. All .class files are given to dx tool to generate a single dex file. The dex file is given to the Dalvik VM to generate the final machine code. The final machine code is given to the CPU to execute.

.apk file contains .dex file in zip format which can be run on Dalvik VMs

Do clap 👏🏻👏🏻 50 times and share the article if you like it. Thank you for giving your valuable time.

--

--

Saumya Singh
Coding Blocks

GHCI Scholar | International Open Source Award Finalist👩‍🎓 ️| SIH Winner