This document provides an overview of Android and Kotlin for mobile app development. It discusses Android versions and history starting from 2008. It also covers Kotlin as a modern programming language that is fully compatible with Java and highly integrated with Android. The document demonstrates basic Kotlin syntax and concepts. It provides examples of how to write Android apps using Java or Kotlin in Android Studio, including activities, layouts, intents, and the recycler view. It also briefly introduces architectural concepts like MVVM and libraries like Retrofit for network requests.
4. Android
● Start from 2008
● Android 13 this year
● App normally written in Java / Kotlin
● Mostly in Phone, but also TV, car & watch
● App can also run in Windows 11, Chromebook
18. Optional Chaining
var a: String? = null
val b: Int? = a?.substring(7)?.length
val c: Int = a?.substring(7)?.length ?: 0
val d: Int = a?.substring(7)?.length!!
30. How to write Android Apps
● Java / Kotlin
● Android Studio
31. Android Studio
● Android IDE base on IntelliJ IDEA
○ IntelliJ IDEA is built by JetBrain, who built Kotlin
● Include full functionality we need
○ Build / Debug / Profile / Logging
○ Android SDK / Emulator management
○ Layout Preview / Inspect
● https://developer.android.com/studio
51. Adapter
class MyAdapter : RecyclerView.Adapter<MyViewHolder>() {
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): MyViewHolder
override fun getItemCount(): Int
override fun onBindViewHolder(
holder: MyViewHolder,
position: Int)
}
58. Model
data class Repo(
val id: Int,
val name: String,
val owner: User
)
data class User(
val id: Int,
@SerializedName("avatar_url")
val avatarUrl: String
)
59. Api Class
interface GitHubService {
@GET("users/{user}/repos")
fun listRepos(
@Path("user") user: String,
@Query("type") type: String? = null,
@Query("sort") sort: String? = null
): Call<List<Repo>>
}
60. Generate Instance
val retrofit = Retrofit.Builder()
.baseUrl("https://api.github.com")
.addConverterFactory(GsonConverterFactory.create())
.build()
val service = retrofit.create(GitHubService::class.java)