├── LICENSE
└── README.md
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Sagar Khurana
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android interview questions that I've faced so far or I think is important
2 |
3 | > I'm creating this repository after getting rejected from ShareChat
4 |
5 | ## Android Components
6 | ### Explain briefly all the Android application components
7 |
8 | **App components** are the essential building blocks of an Android app. Each component is an entry point through which the system or a user can enter your app.
9 | There are four different types of app components :
10 |
11 | * **Activities** - An activity is the entry point for interacting with the user. It represents a single screen with a user interface.
12 | * **Services** - A service is a general-purpose entry point for keeping an app running in the background for all kinds of reasons. It is a component that runs in the background to perform long-running operations or to perform work for remote processes.
13 | * **Broadcast receivers** - A broadcast receiver is a component that enables the system to deliver events to the app outside of a regular user flow, allowing the app to respond to system-wide broadcast announcements.
14 | * **Content providers** - A content provider manages a shared set of app data that you can store in the file system, in a SQLite database, on the web, or on any other persistent storage location that your app can access.
15 |
16 | ### What is an Activity?
17 |
18 | An **activity** provides the window in which the app draws its UI. This window typically fills the screen, but may be smaller than the screen and float on top of other windows. Generally, one activity implements one screen in an app. For instance, one of an app’s activities may implement a Preferences screen, while another activity implements a Select Photo screen.
19 |
20 | --------------
21 | ## Activity Lifecycle
22 | ### Activity Lifecycle (in execution order) -
23 |
24 | | Method | Called When |
25 | |---|---|
26 | | onCreate() | Activity is first created. |
27 | | onStart() | Activity is becoming visible to the user. |
28 | | onResume() | Activity will start interacting with the user. |
29 | | onPause() | Activity is not interactable to the user. |
30 | | onStop() | Activity is no longer visible to the user. |
31 | | onRestart() | After activity is stopped, prior to start. |
32 | | onDestroy() | Before activity is destroyed. |
33 |
34 | >*Note - The onCreate() and onDestroy() methods are called only once throughout the activity lifecycle.
35 |
36 |
37 | ### Uses case of activity lifecycle with execution order
38 |
39 | ##### **When activity is opened:**
40 | ```kotlin
41 | onCreate()
42 |
43 | onStart()
44 |
45 | onResume()
46 | ```
47 | ##### **When moved to another activity:**
48 | > Here A == first activity and B == second activity
49 |
50 | ```kotlin
51 | onPause() - (A)
52 |
53 | onCreate() - (B)
54 |
55 | onStart() - (B)
56 |
57 | onResume() - (B)
58 |
59 | onStop() - (A)
60 | ```
61 |
62 | ##### **When another activity is closed and moving back to first activity:**
63 |
64 | ```kotlin
65 | onPause() - (B)
66 |
67 | onRestart() - (A)
68 |
69 | onStart() - (A)
70 |
71 | onResume() - (A)
72 |
73 | onStop() - (B)
74 |
75 | onDestroy() - (B)
76 | ```
77 |
78 | ### onStart vs onResume
79 | **onStart()** -> called when the activity becomes visible, but might not be in the foreground (e.g. an AlertFragment is on top or any other possible use case).
80 |
81 | **onResume()** -> called when the activity is in the foreground, or the user can interact with the Activity.
82 |
83 | ### onPause vs onStop
84 | **onPause()** -> If you can still see any part of it (Activity coming to foreground either doesn't occupy the whole screen, or it is somewhat transparent).
85 |
86 | **onStop()** -> If you cannot see any part of it
87 |
88 |
89 | A dialog, for example, may not cover the entire previous Activity, and this would be a time for onPause() to be called
90 |
91 |
92 | ## 5 Anti patterns in android
93 | - **Using base classes**: Causes the tight coupling
94 | - **Putting all dependencies in AppModule**: Hard to read and during testing, we can't get the specific module
95 | - **Using one activity per screen**: Activity is heavy as it uses intent to open which internally talks to the android system and the fragment is similar to displaying a layout.
96 | - **Hardcoding dispatchers**: It forces the coroutine to use the particular dispatcher whereas in testing we need to pass the test dispatcher.
97 | - **Using GlobalScope**: Its keeps running during the application process and doesn't care about the lifecycle of the component which causes memory leak or dead object exception.
98 |
99 | Thanks to Philipp Lackner for making a video on this - Link
100 |
101 |
102 | ## 6 Design pattern every android developer must know
103 | - Singleton
104 | - Factory
105 | - Builder
106 | - Facade
107 | - Dependency Injection
108 | - Adapter
109 |
110 | Thanks to Philipp Lackner for making a video on this - Link
111 |
112 |
113 | ## SOLID stands for:
114 | S - Single-responsiblity Principle
115 |
116 | O - Open-closed Principle
117 |
118 | L - Liskov Substitution Principle
119 |
120 | I - Interface Segregation Principle
121 |
122 | D - Dependency Inversion Principle
123 |
124 | > Summary: We can say that the Single Responsibility Principle is about actors and high level architecture. The Open/Closed Principle is about class design and feature extensions. The Liskov Substitution Principle is about subtyping and inheritance. The Interface Segregation Principle (ISP) is about business logic to clients communication. And the Dependency Inversion Principale (DIP) is about leads or helps us respect all the other principles.
125 |
126 | Thanks to Abderrazak Laanaya for writing a article on this - Link
127 |
128 | ## General Questions
129 |
130 | - Tell me about Jetpack Libraries
131 | - Why shoud we use an app architecture and what are the best practices? read
132 | - What are Services, Broadcast receivers and Content providers? read
133 | - Tell me about the Manifest file, what is it's role? read
134 | - Difference between const and val? - val variable is initialized at runtime and const at compile time. Read more here
135 | - Diffrence between sp and dp - sp is same as dp, just android resizes it based on font size set by user.
136 | - What are diffrent Launch modes in android? read
137 | - What are implicit and explicit intents? read
138 | - What makes kotlin the best language for native development? read
139 | - Explain the internal working of a RecyclerView. read
140 | - On which thread would you update the UI components?- Main thread.
141 | - What are companion objects? read
142 | - Fragment lifecycle read
143 | - What are the diffrences between MVVM, MVC and MVP? read
144 | - How would you implement DI in your preferred architechure.
145 | - How is Interface useful in your architechure.
146 | - How to interact with other apps? read
147 | - How to use vibration in our app? read
148 | - Tell me about Dependency Injection
149 | - What is NDK and why is it used?read
150 | - What is the diffrence between .apk and .aab? read
151 | - What is databinding? read
152 | - What is a multi-modular app? read
153 | - What is KAPT? read
154 | - What is Diamond problem in Java? read
155 |
156 | ## What is expected that you know
157 | - Basics of oops classes, inheritance, encapsulation, polymorphism and all of that stuff
158 | - Basic Data sturctures knowledge and problem solving skills
159 | - Basics of Database (eg SQL)
160 | - Basic Operating System knowledge (eg. Threads, cpu scheduling)
161 | - Basic Computer Science curriculum knowledge
162 | - Design patterns
163 | - Standard library functions of Java/Kotlin
164 | - Major Views and how to load data in them
165 | - Internal Working of Activities, Tasks & Stacks
166 |
--------------------------------------------------------------------------------