This presentation covers the next topics:
- Gosling`s/Oracle Classic Java for Devices. Bad Choice for Modern Devices
- What they don't want you to know. Android is a Linux reincarnation. How Linux starts your apk.
- Java in Android Ecosystem
- Common troubles with JLS
- Java Best Practices on Android
This presentation was held by Anatoliy Odukha (Consultant, GlobalLogic) at GlobalLogic Ivano-Frankivks TechTalk on December 1, 2018.
4. 4
Introduction
• GL Lviv, Ukraine
• Consultant, Android and Java/C++ developer
• Worked on Windows Mobile, Symbian,
BlackBerry apps
• 17+ years in IT last 10 with mobile
• Lover of knowledge sharing
• Questions are allowed and welcome
Anatoliy Odukha
5. 5
Today’s Goals
• Java for Mobile devices. A bit of History
• Quick overview How Android works
• Knowledge gap in Java
• Practical cases with Java on Android
6. 6
Learning curve for Java + Android
• Start with Android API and coding
• Java is secondary/utility skill
• Project oriented skill development
Most common case in real world
12. 12
Booting Android
• First/Second stage bootloader
• Start kernel
• Android init process
• app_process aka “Zygote”
• Where is JVM???
13. 13
init process
• Android specific implementation: the Android
Init Language
• /init.rc primary rc file
• Actions, Commands, Services and Imports
on <trigger> [&& <trigger>]*
<command>
14. 14
app_process
• C++ application
• Fork existing ‘zygote’ instead of loading new
process from scratch
• really is more complicated. E.g. start of system
services
15. 15
Sandbox concept
• Limit resource usage per app
• Isolate data.
• Mostly based on Linux permission/users
• Multi-user support in Android
16. 16
ART, Dalvic, DEX, dex2oat
• Main goal is Efficient VM
• ART available since 4.4
• Dalvic (odex), ART(oat)
• Use dex2oat at install time
• First boot may take lots time
•
18. 18
Java 6, Java 7, Java 8 and maybe 9….
• Android does not adapt lates java specs ASAP
• Retrolamba, Jack
• Official: Android Studio 3.0 and later supports
all Java 7 language features and a subset of
Java 8 language features that vary by platform
version.
• Kotlin?
19. 19
Remember all keywords (about 50)
• Usually programmers have issues with:
• goto or break/continue with label
• volatile
• transient
20. 20
Package level access
• Java provide language level tool to implement
OOP/OOD. Use them.
• Design for Change
• Component independence
• High cohesion
• Low coupling
• Exception identification and handling
• Fault Prevention and Fault tolerance
22. 22
Concurrency Framework: God Forsaken Land
• Multi-Threading is hard to understand area
• RxJava does not remove requirement to know
how java way
23. 23
Deadlock
• What is a deadlock?
• How do you detect them?
• Do you handle them?
• And finally, how do you prevent them from
occurring?
Questions
• Thread pools in java?
• AsyncTask
• Static is dangerous
• Background task
Questions on Android
27. 27
Singleton
• Enum based
• Double checked
• Use Application class
• Bad practice for funs of Test Driven
Development
28. 28
Pass data between thread
• Handler and Looper
• Eventbus pattern
• LocalBroadcastManager
• 3rd party libraries
• custom implementation on top of Rx
29. 29
Managing memory issues
• Sandbox limitation
• Single photo from 12Mp camera takes about
48Mb in memory
• Loading on UI thread degrades performance
• Managing multiple bitmaps: memory
management and disk caching
• For real-word app the best solution are 3rd
party lib: picasso, glide