What is the Android Activity Lifecycle?
The Android Activity Lifecycle consists of methods like onCreate(), onStart(), onResume(),
onPause(), onStop(), onRestart(), and onDestroy(). These represent different states of an
activity as it is created, paused, resumed, or destroyed by the system.
What’s the difference between onCreate(), onStart(), and onResume()?
onCreate(): Called when the activity is first created. onStart(): Called when the activity
becomes visible to the user. onResume(): Called when the activity starts interacting with
the user.
What are Fragments?
Fragments are reusable UI components that represent a portion of a UI in an Activity. They
have their own lifecycle and can be combined to create multi-pane layouts.
How does onSaveInstanceState() work and when is it called?
onSaveInstanceState() is called before the activity is destroyed, so that data can be saved
and restored during configuration changes like screen rotations.
What are the different launch modes in Android?
standard, singleTop, singleTask, and singleInstance - these define how activities are
launched and managed in the back stack.
What is Context in Android?
Context is an abstract class in Android that allows access to application-specific resources
and classes. ApplicationContext is tied to the app lifecycle, while ActivityContext is tied to
the activity lifecycle.
Explain Intent and its types.
Intent is a messaging object used to request an action. Explicit Intent targets a specific
component, while Implicit Intent allows other apps to handle the request.
What is the difference between View.GONE, View.INVISIBLE, and
View.VISIBLE?
VISIBLE: The view is visible. INVISIBLE: The view is hidden but still takes space. GONE:
The view is completely hidden and doesn’t take space.
How do you handle screen orientation changes?
Use `onSaveInstanceState()` to save data or declare
`android:configChanges="orientation|screenSize"` in the manifest.
What is Jetpack Navigation Component?
It simplifies navigation and UI transitions, handles back stack automatically, and works
well with ViewModels and Fragments.
What are RecyclerView and Adapter?
RecyclerView is a more advanced and flexible version of ListView. Adapter provides data
to the RecyclerView and creates ViewHolders.
What is the View Binding vs Data Binding?
View Binding is simpler and type-safe. Data Binding allows binding UI components to data
sources using expressions in XML.
What are the main ways to perform background tasks?
Threads, Handler, AsyncTask (deprecated), Coroutines, WorkManager, JobScheduler,
etc.
Explain the differences between Handler, HandlerThread, and Looper.
Handler: Posts tasks to a thread's message queue. HandlerThread: A thread with a
Looper. Looper: Runs the message loop for a thread.
What is WorkManager?
WorkManager is used for deferrable, guaranteed background work that needs to be
executed even if the app exits or the device restarts.
How do Coroutines work in Android?
Coroutines provide an easy way to write asynchronous code. launch starts a new
coroutine, async returns a Deferred, and suspend functions can suspend execution
without blocking the thread.
What is the difference between SharedPreferences, SQLite, and Room?
SharedPreferences: Key-value pairs. SQLite: Relational database. Room: Abstraction
layer over SQLite with compile-time checks.
How do you store sensitive data?
Use EncryptedSharedPreferences, Android Keystore, or use secure storage libraries like
Jetpack Security.
What are ContentProviders?
They manage access to structured data and provide a standard interface to access and
modify data from different apps.
What is MVVM in Android?
Model-View-ViewModel (MVVM) separates business logic and UI. ViewModel holds data
and logic, LiveData is used for observation, and View reflects changes.
What is Dependency Injection?
It’s a design pattern to inject dependencies instead of creating them manually. Hilt and
Dagger are popular libraries for DI in Android.
How do you make network requests in Android?
Use libraries like Retrofit or OkHttp. Retrofit simplifies REST API calls and supports
GSON/JSON parsing.
What is Retrofit?
Retrofit is a type-safe HTTP client for Android. It uses annotations to describe HTTP
requests and responses and integrates with Gson for JSON parsing.
What are ANRs?
Application Not Responding (ANR) occurs when the main thread is blocked for more than
5 seconds. Avoid long operations on the main thread to prevent ANRs.
How do you handle memory leaks?
Use weak references, avoid static references to Context, unregister listeners, and monitor
memory with tools like LeakCanary.