Whats new in Android

Whats new in Android

Lecture at University of malta as part of DevFest Malta

A8b79d304b5184e5a5b0a109590f6683?s=128

Danny Preussler

November 17, 2017
Tweet

Transcript

  1. WHAT’S HOT IN GDG Malta Danny Preussler @PreusslerBerlin

  2. WHO’S THAT GERMAN?

  3. WHAT’S A DEVELOPER EXPERT?

  4. WHAT’S A DEVELOPER EXPERT?

  5. 2009 ANDROID

  6. SOOO 2016 • Material Design • Firebase • ConstraintLayout •

    Databinding • RxJava
  7. SOOO 2016 • Material Design • Firebase • ConstraintLayout •

    Databinding • RxJava
  8. SOOO 2016 • Material Design • Firebase • ConstraintLayout •

    Databinding • RxJava
  9. SOOO 2016 • Material Design • Firebase • ConstraintLayout •

    Databinding • RxJava
  10. SOOO 2016 • Material Design • Firebase • ConstraintLayout •

    Databinding • RxJava
  11. SOOO 2016 • Material Design • Firebase • ConstraintLayout •

    Databinding • RxJava
  12. SOOO 2016 • Material Design • Firebase • ConstraintLayout •

    Databinding • RxJava ViewModel View
  13. DATA BINDING

  14. SOOO 2016 • Material Design • Firebase • ConstraintLayout •

    Databinding • RxJava
  15. RXJAVA tasksRepository.getTasks() .flatMap(Flowable::fromIterable) .filter(task -> { switch (currentFiltering) { case

    ACTIVE_TASKS: return task.isActive(); case COMPLETED_TASKS: return task.isCompleted(); case ALL_TASKS: default return true; } }) * https://github.com/googlesamples/android-architecture
  16. WHAT WAS NEW IN 2017

  17. NEW FEATURE IN ANDROID 8 • Picture in Picture •

    Resizable TextView • Fonts in xml and Downloadable fonts • Notification changes • Background changes • Instant Apps
  18. • Picture in Picture • Resizable TextView • Fonts in

    xml and Downloadable fonts • Notification changes • Background changes • Instant Apps
  19. NEW FEATURE IN ANDROID 8 • Picture in Picture •

    Resizable TextView • Fonts in xml and Downloadable fonts • Notification changes • Background changes • Instant Apps
  20. NEW FEATURE IN ANDROID 8 • Picture in Picture •

    Resizable TextView • Fonts in xml and Downloadable fonts • Notification changes • Background changes • Instant Apps
  21. NEW FEATURE IN ANDROID 8 • Picture in Picture •

    Resizable TextView • Fonts in xml and Downloadable fonts • Notification changes • Background changes • Instant Apps
  22. NEW FEATURE IN ANDROID 8 • Picture in Picture •

    Resizable TextView • Fonts in xml and Downloadable fonts • Notification changes • Background changes • Instant Apps
  23. BACKGROUND CHANGES • Doze and JobScheduler started with M (Android

    6) • New background limitations
  24. NEW FEATURE IN ANDROID 8 • Picture in Picture •

    Resizable TextView • Fonts in xml and Downloadable fonts • Notification changes • Background changes •Instant apps
  25. INSTANT APPS • “say no to app downloads” • (partial)

    app starts directly from website • Split up your app into feature modules
  26. NEWS IN ARCHITECTURE • Architecture blueprints • Architecture guidelines •

    Architecture components
  27. NEWS IN ARCHITECTURE •Architecture blueprints github.com/googlesamples/android-architecture • Architecture guidelines •

    Architecture components
  28. NEWS IN ARCHITECTURE • Architecture blueprints •Architecture guidelines developer.android.com/topic/libraries/architecture/guide.html •

    Architecture components
  29. NEWS IN ARCHITECTURE • Architecture blueprints •Architecture guidelines • Architecture

    components
  30. None
  31. NEWS IN ARCHITECTURE • Architecture blueprints • Architecture guidelines •Architecture

    components developer.android.com/topic/libraries/architecture/index.html
  32. ARCHITECTURE COMPONENTS • Viewmodel • LiveData • LifeCycleObserver • Room

    • Pagination
  33. VIEWMODEL • provides the data for a specific UI •

    fits great into MVVM • survives configuration change
  34. VIEWMODEL • provides the data for a specific UI •

    fits great into MVVM • survives configuration change
  35. VIEWMODEL • provides the data for a specific UI •

    fits great into MVVM • survives configuration change Model ViewModel View
  36. VIEWMODEL • provides the data for a specific UI •

    fits great into MVVM • survives configuration change
  37. VIEWMODEL public void onCreate(...) { model = ViewModelProviders .of(this) .get(MyViewModel.class);

    } class MyViewModel extends ViewModel { …
  38. VIEWMODEL LIVES LONGER! Activity Activity ViewModel

  39. INTRODUCING LIVE DATA Activity Activity LiveData LiveData ViewModel

  40. LIVE DATA • Observable similar to RxJava • Life cycle

    aware • Doesn’t emit when not needed • Memory leak save
  41. LIVE DATA • Observable similar to RxJava • Life cycle

    aware • Doesn’t emit when not needed • Memory leak save
  42. LIVE DATA • Observable similar to RxJava • Life cycle

    aware • Doesn’t emit when not needed • Memory leak save
  43. LIVE DATA • Observable similar to RxJava • Life cycle

    aware • Doesn’t emit when not needed • Memory leak save
  44. LIVE DATA • Observable similar to RxJava • Life cycle

    aware • Doesn’t emit when not needed • Memory leak save
  45. LIVE DATA class MyViewModel extends ViewModel { MutableLiveData<String> message =

    new MutableLiveData<String>(); myModel.message.observe(this, new Observer<String>() { @Override public void onChanged(String newValue) {..} }
  46. LIFECYCLEOBSERVER • Helps building your own life cycle aware components

    • Watch Activity, Fragment or Application life cycle • Avoid memory leaks • Avoid forwarding events from activities/fragments • Introduces ProcessLifeCycle!
  47. ROOM • SQLite Object Mapper • Compile time check •

    Works with RxJava
  48. ROOM @Dao abstract class ConferenceStore { @Insert abstract void insert(List<Session>

    sessions); @Query("SELECT * FROM tracks") abstract List<Track> allTracks(); ... https://commonsware.com/presos/2017-11-Room
  49. ROOM @Entity(tableName = "tracks") class Track { @PrimaryKey(autoGenerate = true)

    final Long id; @NonNull final String title; @NonNull final String location; ... https://commonsware.com/presos/2017-11-Room
  50. ROOM @Database(version=1, entities = {Track.class, Session.class}) abstract public class ConferenceDatabase

    extends RoomDatabase { https://commonsware.com/presos/2017-11-Room
  51. A NEW PROGRAMMING LANGUAGE * Java still fully supported on

    Android
  52. KOTLIN • Modern language • Reduce boilerplate • null safe

    • New possibilies • Communication with swift devs • Works great with Java • Multiplatform with web and backend
  53. KOTLIN • Modern language • Works great with Java •

    Reduce boilerplate • null safe • New possibilies • Communication with swift devs • Multiplatform with web and backend
  54. KOTLIN • Modern language • Works great with Java •

    Reduce boilerplate • null safe • New possibilies • Communication with swift devs • Multiplatform with web and backend
  55. fun isEligibleToVote(): Boolean { return age >= 18 }

  56. fun isEligibleToVote = age >= 18

  57. data class MyModel(val lastName: String, val name: String = “”)

  58. ... Map<TYPE, Integer> signalStrength = new HashMap<>(); signalStrength.put(EDGE, 80); signalStrength.put(WIFI

    to 90); ...
  59. ... val signalStrength = hashMapOf(EDGE to 80, WIFI to 90)

    ...
  60. class MyViewModel extends ViewModel { MutableLiveData<String> message = new MutableLiveData<String>();

    myModel.message.observe(this, new Observer<String>() { @Override public void onChanged(String newName) {..} }
  61. class MyViewModel(): ViewModel(){ val message = MutableLiveData<String>() myModel.message.observe(this, Observer{ ..

    })}
  62. KOTLIN • Modern language • Works great with Java •

    Reduce boilerplate • null safe • New possibilies • Communication with swift devs • Multiplatform with web and backend
  63. NULL SAFETY var canNeverBeNull: String var canBeNull: String?

  64. if (subscription != null) { subscription.dispose() }

  65. subscription?.dispose()

  66. KOTLIN • Modern language • Works great with Java •

    Reduce boilerplate • null safe • New possibilities • Communication with swift devs • Multiplatform with web and backend
  67. val typeOfPerson = when(age){ 0 -> "New born" in 1..12

    -> "Child" in 13..19 -> "Teenager" else -> "Adult" }
  68. fun String.toAspectRatio(): AspectRatio? = when (this) { "1:1" -> ONE_BY_ONE

    "2:3" -> TWO_BY_THREE else -> null }
  69. fun Int.clamp(lower: Int, upper: Int) = Math.max(lower, Math.min(this, upper)) progress.clamp(0,

    100)
  70. greeting shouldEqual "hello"

  71. greeting.shouldEqual("hello”)

  72. greeting shouldEqual "hello"

  73. greeting `should equal` "hello"

  74. KOTLIN • Modern language • Works great with Java •

    Reduce boilerplate • null safe • New possibilities • Communication with swift devs • Multiplatform with web and backend
  75. KOTLIN • Modern language • Works great with Java •

    Reduce boilerplate • null safe • New possibilities • Communication with swift devs • Multiplatform with web and backend support for JVM, JS, native
  76. KOTLIN = fun

  77. None
  78. SUMMARIZE It was never so easy to start with Android

  79. WRITE ANDROID IN

  80. ANDROID IS MORE THAN PHONE

  81. None
  82. WHAT’S HOT IN GDG Malta Danny Preussler @PreusslerBerlin