Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Living on a green rocket field - GDG Berlin And...

Hasan Hosgel
September 26, 2018

Living on a green rocket field - GDG Berlin Android meetup

At Google IO 2018 the Android team announced Jetpack for Android, which is an opinionated set of libraries and architecture, which is a recommendation for Android developers. We wanted to share our experience with Jetpack and also give some recommendations for all the library & SDK developers.

Hasan Hosgel

September 26, 2018
Tweet

More Decks by Hasan Hosgel

Other Decks in Technology

Transcript

  1. @alosdev GDG Berlin Android 09 Timetable 2011/03 - 1st version

    Support Library - ActionBarSherlock 2012/03 - Notification Compat 2013/07 - App Compat, Media Router 2014/10 - RecyclerView, CardView 2015/08 - bunch of new libraries 2016/08 - split support libs 2017/06 - multidex … source: https://developer.android.com/topic/libraries/support-library/revisions
  2. @alosdev GDG Berlin Android 09 Android KTX Kotlin Extension for

    a bunch of jetpack libraries: • Core-ktx • Fragment-ktx • Lifecycle-ktx • navigation-ktx
  3. @alosdev GDG Berlin Android 09 Architecture libraries • DataBinding •

    Lifecycles • LiveData • Navigation • Paging • Room • ViewModel • WorkManager NEW NEW NEW
  4. @alosdev GDG Berlin Android 09 Navigation • Navigation Controller •

    “easily” update in a wysiwyg editor, also via xml • new resource type navigation
  5. @alosdev GDG Berlin Android 09 Navigation graph <navigation … app:startDestination="@id/blankFragment">

    <fragment android:id="@+id/blankFragment" android:name="com.example.cashdog.cashdog.BlankFragment" android:label="fragment_blank" tools:layout="@layout/fragment_blank" /> <fragment android:id="@+id/blankFragment2" android:name="com.example.cashdog.cashdog.BlankFragment2" android:label="Blank2" tools:layout="@layout/fragment_blank_fragment2" /> </navigation>
  6. @alosdev GDG Berlin Android 09 Layout file <android.support.constraint.ConstraintLayout … android:layout_width="match_parent"

    android:layout_height="match_parent" tools:context=".MainActivity"> <fragment android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/my_nav_host_fragment" android:name="androidx.navigation.fragment.NavHostFragment" app:navGraph="@navigation/nav_graph" app:defaultNavHost="true"/> </android.support.constraint.ConstraintLayout>
  7. @alosdev GDG Berlin Android 09 Parameterized navigation <fragment android:id="@+id/confirmationFragment" android:name="com.example.cashdog.cashdog.ConfirmationFragment"

    android:label="fragment_confirmation" tools:layout="@layout/fragment_confirmation"> <argument android:name="amount" android:defaultValue=”0” /> var bundle = bundleOf("amount" to amount) view.findNavController().navigate(R.id.confirmationAction, bundle)
  8. @alosdev GDG Berlin Android 09 Parameterized navigation with TypeSafety Build.gradle:

    … apply plugin: 'androidx.navigation.safeargs' … Caller side: val action = SpecifyAmountFragmentDirections.confirmationAction(amount) action.amount = amount v.findNavController().navigate(action) Consumer side: ConfirmationFragmentArgs.fromBundle(arguments).amount
  9. @alosdev GDG Berlin Android 09 Navigation in Multi Modules •

    Include existing navigation graph • Module dependency on the navigation graph you want to use • If you don’t want to depend on the other module, define the resource id in the base ◦ no TypeSafety
  10. @alosdev GDG Berlin Android 09 Paging • PagedList as data

    object • DataSource to serve PageList • PagedListAdapter for RecyclerView Attention: if you want to manipulate the List itself that is not the way to go
  11. @alosdev GDG Berlin Android 09 WorkManager • Successor of JobScheduler,

    JobDispatcher & AlarmManager • Not depending on Google play services (GMS) ◦ Usage outside of Google ecosystem • Defining constraints, when to run them ( charging, network, etc.)
  12. @alosdev GDG Berlin Android 09 Worker class CompressWorker(context : Context,

    params : WorkerParameters) : Worker(context, params) { override fun doWork(): Result { // Do the work here--in this case, compress the stored images. // In this example no parameters are passed; the task is // assumed to be "compress the whole library." myCompress() // Indicate success or failure with your return value: return Result.SUCCESS // (Returning RETRY tells WorkManager to try this task again // later; FAILURE says not to try again.) } }
  13. @alosdev GDG Berlin Android 09 Constraint // Create a Constraints

    object that defines when the task should run val myConstraints = Constraints.Builder() .setRequiresDeviceIdle(true) .setRequiresCharging(true) // Many other constraints are available, see the // Constraints.Builder reference .build()
  14. @alosdev GDG Berlin Android 09 Running them // ...then create

    a OneTimeWorkRequest that uses those constraints val compressionWork = OneTimeWorkRequestBuilder<CompressWorker>() .setConstraints(myConstraints) .build() OR val compressionWork = PeriodicWorkRequestBuilder<CompressWorker>(12, TimeUnit.HOURS) .setConstraints(myConstraints) .build() // Then enqueue the recurring task: WorkManager.getInstance().enqueue(compressionWork)
  15. @alosdev GDG Berlin Android 09 Worker chains val chain1 =

    WorkManager.getInstance() .beginWith(workA) .then(workB) val chain2 = WorkManager.getInstance() .beginWith(workC) .then(workD) val chain3 = WorkContinuation .combine(chain1, chain2) .then(workE) chain3.enqueue()
  16. @alosdev GDG Berlin Android 09 Behaviour libraries • Download Manager

    • Media & Playback • Notifications • Permission • Sharing • Slices NEW
  17. @alosdev GDG Berlin Android 09 Slices • Currently not visible

    for users, but you can be first movers • Like widgets for the home screen, just in other apps • Supported API level 19 (KitKat) onwards • Can be used with Actions
  18. @alosdev GDG Berlin Android 09 UI libraries • Animation &

    transitions • Auto • Emoji • Fragment • Layout • Palette • TV • Wear OS by Google
  19. @alosdev GDG Berlin Android 09 Wishlist for libraries/ SDKs •

    Don’t force your user to a specific marshaller (GSON, Jackson, Moshi) ◦ Offer the functionality like Retrofit and the ConverterFactory • Don’t force your user to use Rx- there is a cool guy around => Coroutine ◦ Droidcon Panel discussion “Rx must die!?” ◦ From Rx monolith to Coroutines + multi modules by Ivan Morgillo • Don’t depend on bigger libraries, especially if just use a small part of it • Add proguard config in your Jar/ Aar and don’t widen it to much