This document summarizes different programming language options for Android development and discusses their advantages and disadvantages. It focuses on Scala, noting that while it is statically typed, compiles to Java bytecode, and allows access to all Android classes, performance can sometimes be slow. It provides examples of how to use Scala features like type inference, imports, lazy vals, mixins, collections, functions, pattern matching, implicits, and XML processing. It also cautions that performance sensitive parts may require removing features like for-comprehensions and avoiding boxed types.
2. Android Development
● Write lots of Java code
● Write UI and other resources in XML
● Generate Java code from resources
● Compile Java code into “.class” files
● Run proguard
● Compile class files to Dalvik Executable (DEX)
● Deploy on device
3. Dalvik VM
● Does not support “.class” bytecode format
● Can not use libraries which generate bytecode
● Devices have limited CPU and Memory
● Can not easily share libraries between
applications
4. Eclipse
● Has nice UI editors
● IDE is a build tool
12. Scala
● Statically typed
● Compiled to Java bytecode
● Has access to all classes in Android
● Fast
● but sometimes slow :)
● Has SBT
● Android
● Maven artifacts
13. How to build Scala apps for Android
● ANT
● Maven
● SBT + Android Plugin
20. Collections
● Best collection library I ever used
● Sorry google-collections...
● Using arrays is easy
● @specialized
21. Collection examples
val suggestions = areas map { _.name }
val index = areas.indexWhere(
_.name == searchString
)
val index =
areas.indexWhere(_.contains(coordinate))
pointList.minBy(_.lat)
22. First class functions
class AreaOverlay(
areas: Array[Area],
selectListener: Int => Unit
)
new AreaOverlay(
areas, this.onAreaSelected
)
23. Convert listeners into functions
implicit def fn2ClickListener(
f: View => Unit
): View.OnClickListener =
new View.OnClickListener() {
override def onClick(v: View) = f(view)
}
exitButton.setOnClickListener(
this.onExitClick
)
24. Files
● Directory structure is not forced to mirror
packages
● Files can contain any amount of classes
25. Pattern matching
● No NPEs when using Option[T]
● Easy to work with data objects
28. XML
for (s <- xml "Document" "Style")
placemarkElem "Polygon"
"outerBoundaryIs" "LinearRing"
"coordinates"
29. Bad stuff
● Performance sensitive parts
● Learn to use “javap”
● Remove for-comprehensions and lambda functions
● Do not use boxed types “by accident”
● Tools
● UI Editor
● Debugger
● Build time (dex'ing of scala library)
30. What I missed from Java
● Google Guice
● Maven
● Good Eclipse integration
● Feeling important...