Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Android with Kotlin
Search
Ahmed Tarek
October 12, 2017
Programming
0
150
Android with Kotlin
Slides from my talk Android with Kotlin at Oct 2017 GDG 6 October City, Egypt.
Ahmed Tarek
October 12, 2017
Tweet
Share
Other Decks in Programming
See All in Programming
What's new in AppKit on macOS 26
1024jp
0
110
すべてのコンテキストを、 ユーザー価値に変える
applism118
3
1.4k
Android 16KBページサイズ対応をはじめからていねいに
mine2424
0
130
A full stack side project webapp all in Kotlin (KotlinConf 2025)
dankim
0
120
なんとなくわかった気になるブロックテーマ入門/contents.nagoya 2025 6.28
chiilog
1
280
技術同人誌をMCP Serverにしてみた
74th
1
660
Node-RED を(HTTP で)つなげる MCP サーバーを作ってみた
highu
0
120
『自分のデータだけ見せたい!』を叶える──Laravel × Casbin で複雑権限をスッキリ解きほぐす 25 分
akitotsukahara
2
640
High-Level Programming Languages in AI Era -Human Thought and Mind-
hayat01sh1da
PRO
0
800
状態遷移図を書こう / Sequence Chart vs State Diagram
orgachem
PRO
1
130
型で語るカタ
irof
0
200
Team operations that are not burdened by SRE
kazatohiei
1
320
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
69
11k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
A Modern Web Designer's Workflow
chriscoyier
695
190k
Fireside Chat
paigeccino
37
3.5k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
700
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Optimizing for Happiness
mojombo
379
70k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
Reflections from 52 weeks, 52 projects
jeffersonlam
351
20k
How to train your dragon (web standard)
notwaldorf
96
6.1k
Transcript
Android with Kotlin a_tarek360 Oct, 2017
What is kotlin?
Kotlin is a Russian island
Kotlin • By JetBrains in 2011 • Open sourced in
2012 • The first officially stable release in 2016
At Google I/O 2017, Google announced..
Kotlin • Official Programming Language for Android Development
Kotlin • Statically typed programming language • 100% interoperable with
Java and Android • Avoid entire classes of errors such as null pointer exceptions.
var / val var name = "Ahmed" val id =
1 Val cannot be reassigned id = 3
Null Safety Safe var name: String name = null //
Compilation error Nullable val name: String? = null // Nullable type println(name.length()) // Compilation error println(name?.length())
Classes/Interfaces class SimpleClass class SimpleClass(value: String) interface SimpleInterface class SimpleClass
: BaseClass(), SimpleInterface
Data Class data class Car( var name: String, var color:
Int, var speed: Float) • No need to implement: toString, equals
Functions fun isMoving(speed: Int): Boolean { return speed > 0
} fun isMoving(speed: Int) = speed > 0
Companion Object class Car { companion object { fun drive()
{ } } } // Like calling a static method Car.drive()
Simple Android Activity class MainActivity : Activity() { override fun
onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val name = savedInstanceState?.getString("name") } }
Extending Language isLollipop { view.elevation = 3.0f } . .
. . inline fun isLollipop(code: () -> Unit) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { code.invoke() } }
Smart Cast fun setData(view: View) { if (view is ImageView)
{ view.setImageDrawable(drawable) } if (view is TextView) { view.setText("hello") } }
Callback/Lambda • view.setOnClickListener(object : View.OnClickListener { override fun onClick(view: View?)
{ doSomething() } }) • view.setOnClickListener { view -> doSomething(view) } • view.setOnClickListener { doSomething() }
Function Parameter Default Value fun toast(message: String) { Toast.toast(this, message,
Toast.LENGTH_LONG).show() } fun toast(message: String, duration: Int) { Toast.makeText(this, message, duration).show() } fun toast(message: String, duration: Int = Toast.LENGTH_LONG) { Toast.makeText(this, message, duration).show() }
Extension Functions fun Activity.toast(message: String, duration: Int = Toast.LENGTH_LONG) {
Toast.makeText(this, message, duration).show() } // Call it from any activity instance toast("Hello World!") toast("Hello World!", Toast.LENGTH_SHORT)
Kotlin Android Extensions <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/photo" … />
<TextView android:id="@+id/name" … /> </RelativeLayout>
Kotlin Android Extensions import kotlinx.android.synthetic.main.activity_main.* override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) photo.setImageBitmap(bitmap) name.setText("Hello World!") }
Thank You!