Loading repository data…
Loading repository data…
SaadAAkash / repository
💼📝⚡️Mobile App Developer Interviews Q&A Cheat Sheet - An awesome curation of Q&A, code examples, resources - categorized based on expertise (Continuously Updating)
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
| 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|
| Android Basics | Android Specifics: Native | Android Specifics: Cross-Platform | Android Intermediate | Android Advanced | Resources & Learning Guides |
There are four different types of app components:
To declare all app components, we use the following elements:
<activity> elements for activities.<service> elements for services.<receiver> elements for broadcast receivers.<provider>elements for content providers.An Intent is a messaging object you can use to request an action from another app component.
Use Cases: Starting an Activity or a Service, Delivering a broadcast.
A PendingIntent object is a wrapper around an Intent object. The primary purpose of a PendingIntent is to grant permission to a foreign application to use the contained Intent as if it were executed from your app's own process.
Use Cases:
This element is used in the Manifest file to declare the capabilities of an app component (i.e. an Activity)
Use Case: When we declare an Activity in the Manifest, we can include intent filters so it can respond to intents from other applications like the following:
<manifest>
...
<application>
<activity android:name="com.example.SendEmailActivity">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<data android:type="*/*" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Link to the resources with graphical explanation:
There are 4 visibility modifiers in Kotlin:
class EventViewModel internal constructor()
In the previous code snippet, internal makes class available to public, but constructor only to inside module
If you need a function or a property to be tied to a class rather than to instances of it, you can declare it inside a companion object. If you declare a companion object inside your class, you'll be able to call its members with the same syntax as calling static methods in Java/C#, using only the class name as a qualifier. It is similar to static keyword in Java or @staticmethod in Python.
companion object {
@Volatile private var instance: EventRepository? = null
fun getInstance(eventDao:EventDao) =
instance ?: synchronized(this) {
instance ?: EventRepository(eventDao).also { instance = it }
}
}
var a: String = "abc"
a = null
var b: String? = "abc"
b = null
print(b)
a =null will produce a compilation errorb = null will not produce any errorval a = "Kotlin"
val b: String? = null
println(b?.length) //prints null
println(a?.length) //prints 6
A quick Overview of some possible cases:
| 1 | 2 | 3 | 4 |
|---|---|---|---|
| a: String? | a.length | a?.length | a!!.length |
| "cat" | Compile time error | 3 | 3 |
| null | Compile time error | null | NullPointerException |
!! is an option for NPE-lovers. a!!.length will return a non-null value of a.length or throw a NullPointerException if a is null. And a?.length returns a.length if a is not null, and null otherwise:
val a: String? = null
print(a!!.length) // >>> NPE: trying to get length of null
val a: String? = null
print(a?.length) // >>> null is printed in the console
val list = mutableList ?: mutableListOf()
is a shorter form of
val list = if (mutableList != null) mutableList else mutableListOf()
The name,howver, comes from the famous American singer Elvis Presley. His hairstyle resembles a Question Mark Ref

1st Code Snippet:
return if (x) foo() else bar()
return when(x) {
0 -> "zero"
else -> "nonzero"
}
2nd Code Snippet:
if (x)
return foo()
else
return bar()
when(x) {
0 -> return "zero"
else -> return "nonzero"
}
The above is preferable to the latter one.
Out Initialization code can be placed in initializer blocks, which are prefixed with the init keyword:
class InitOrderDemo(name: String) {
val firstProperty = "First property: $name".also(::println) //inits a val & also, prints the name
init {
println("First initializer block that prints ${name}")
println("Second initializer block that prints ${name.length}")
}
}
fun main() {
//both of the ways are correct!
test( { println(it) } )
test(::println)
}
fun test(block: (String) -> Unit ) {
block("okay")
}
@Volatile before a field means that writes to this field are immediately made visible to other threads.
In Kotlin, there's no way to check the generic parameters at runtime in general case (like just checking the items of a List<T> or here in this ViewModelFactory, modelClass: Class<T> which is only a special case), so casting a generic type to another with different generic parameters will raise a warning, which needs to be suppressed
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>) = EventViewModel(eventRepository, lifecycleOwner) as T