Slide 1

Slide 1 text

What’s new in Android with Deesha Vora @Deesharv Founder @SuperWiseSite

Slide 2

Slide 2 text

Quick overview - JETPACK - ANDROIDX - DISTRIBUTION - App Bundle - ENGAGEMENT - Slices - ANDROID P

Slide 3

Slide 3 text

JetPack Overview

Slide 4

Slide 4 text

ARCHITECTURE - NAVIGATION (alpha) Principles of Navigation ● The app should have a fixed starting destination ● A stack is used to represent the "navigation state" of an app ● Up and Back are equivalent within your app's task ● Deep linking to a destination or navigating to the same destination should yield the same stack

Slide 5

Slide 5 text

….. ARCHITECTURE - NAVIGATION (alpha) dependencies { def nav_version = "1.0.0-alpha01" implementation "android.arch.navigation:navigation-fragment:$nav_vers ion" // use -ktx for Kotlin implementation "android.arch.navigation:navigation-ui:$nav_version" // use -ktx for Kotlin androidTestImplementation "android.arch.navigation:navigation-testing:$nav_versi on" // use -ktx for Kotlin }

Slide 6

Slide 6 text

….. ARCHITECTURE - NAVIGATION (alpha)

Slide 7

Slide 7 text

….. ARCHITECTURE - NAVIGATION (alpha)

Slide 8

Slide 8 text

ARCHITECTURE - PAGING (1.0.0 Stable) dependencies { def paging_version = "1.0.0" implementation "android.arch.paging:runtime:$paging_version" // alternatively - without Android dependencies for testing testImplementation "android.arch.paging:common:$paging_version" // optional - RxJava support, currently in release candidate implementation "android.arch.paging:rxjava2:1.0.0-rc1" } UI components and considerations Data components and considerations

Slide 9

Slide 9 text

…..ARCHITECTURE - PAGING - DATA Component 1. Construct an observable list 2. Define your own paging configuration 3. Choose the correct data source type Or Build your own data sources 4. Consider how content updates work 5. Provide mapping between data representations

Slide 10

Slide 10 text

…..ARCHITECTURE - PAGING - DATA Component Construct an observable list A DataSource object loads pages for a single PagedList. The factory class creates new instances of PagedList in response to content updates, such as database table invalidations and network refreshes. interface ConcertDao { // The Integer type parameter tells Room to use a PositionalDataSource // object, with position-based loading under the hood. @Query("SELECT * FROM concerts ORDER BY date DESC") public abstract DataSource.Factory concertsByDate() } VIEW MODEL -------------- // The Integer type argument corresponds to a PositionalDataSource object. val myConcertDataSource : DataSource.Factory =concertDao.concertsByDate() val myPagedList = LivePagedListBuilder(myConcertDataSource, 20).build()

Slide 11

Slide 11 text

…..ARCHITECTURE - PAGING - DATA Component val myPagingConfig = PagedList.Config.Builder() .setPageSize(50) .setPrefetchDistance(150) .setEnablePlaceholders(true) .build() val myPagedList = LivePagedListBuilder(myConcertDataSource, myPagingConfig) .setFetchExecutor(myExecutor) .build() Define your own paging configuration Choose the correct data source type PageSize PageKeyedDataSource Prefetch distance ItemKeyedDataSource Placeholder presence PositionalDataSource

Slide 12

Slide 12 text

…..ARCHITECTURE - PAGING - DATA Component Build your own datasource class MyDataSource : ItemKeyedDataSource() { override fun getKey(item: Item) = item.name override fun loadInitial( params: LoadInitialParams, callback: LoadInitialCallback) { val items = fetchItems(params.requestedLoadSize) callback.onResult(items) } override fun loadAfter( params: LoadParams, callback: LoadCallback) { val items = fetchItemsAfter( start = params.key, limit = params.requestedLoadSize) callback.onResult(items) } }

Slide 13

Slide 13 text

…..ARCHITECTURE - PAGING - DATA Component Update current content For Room it happens automatically, but for Refresh action where current DataSource has to be invalidated consider below code class ConcertActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { ... concertViewModel.refreshState.observe(this, Observer { swipeRefreshLayout.isRefreshing = it == NetworkState.LOADING }) swipeRefreshLayout.setOnRefreshListener { concertViewModel.invalidateDataSource() } } }

Slide 14

Slide 14 text

…..ARCHITECTURE - PAGING - DATA Component Provide mapping between data representations class ConcertViewModel : ViewModel() { val concertDescriptions : LiveData> init { val factory = database.allConcertsFactory() .map { concert -> concert.name + " - " + concert.date } concerts = LivePagedListBuilder(factory, 30).build() } } }

Slide 15

Slide 15 text

…..ARCHITECTURE - PAGING - UI Component class ConcertPagedListAdapter() : PagedListAdapter( object : DiffUtil.ItemCallback() { // The ID property identifies when items are the same. override fun areItemsTheSame(oldItem: Concert, newItem: Concert) = oldItem.id = newItem.id // Use the "==" operator (or Object.equals() in Java-based code) to know // when an item's content changes. Implement equals(), or write custom // data comparison logic here. override fun areContentsTheSame(oldItem: Concert, newItem: Concert) = oldItem.name == newItem.name && oldItem.date == newItem.date } ) { override fun onBindViewHolder(holder: ConcertViewHolder, position: Int) { val concert: Concert? = getItem(position) // Note that "concert" is a placeholder if it's null holder.bind(concert) } }

Slide 16

Slide 16 text

ARCHITECTURE - WORK MANAGER WorkManager might use JobScheduler, Firebase JobDispatcher, or AlarmManager based on API level and App state ● Worker: specifies what task you need to perform. The WorkManager APIs include an abstract Worker class. You extend this class and perform the work here. ● WorkRequest: represents an individual task. At a minimum, a WorkRequest object specifies which Worker class should perform (Onetime or Periodic) ● WorkManager ● WorkStatus public class CompressWorker extends Worker { @Override public Worker.WorkerResult doWork() { myCompress(); return WorkerResult.SUCCESS; } } WorkManager.getInstance().getStatusById(compressionWork.getId()) .observe(lifecycleOwner, workStatus -> { if (workStatus != null && workStatus.getState().isFinished()) { ... } });

Slide 17

Slide 17 text

Android KTX

Slide 18

Slide 18 text

Android KTX BEFORE view.viewTreeObserver.addOnPreDrawListener( object : ViewTreeObserver.OnPreDrawListener { override fun onPreDraw(): Boolean { viewTreeObserver.removeOnPreDrawListener(thi s) actionToBeTriggered() return true } }); AFTER view.doOnPreDraw { actionToBeTriggered() }

Slide 19

Slide 19 text

Android KTX BEFORE supportFragmentManager .beginTransaction() .replace(R.id.my_fragment_container, myFragment, FRAGMENT_TAG) .commitAllowingStateLoss() AFTER supportFragmentManager.transaction(allowStateL oss = true) { replace(R.id.my_fragment_container, myFragment, FRAGMENT_TAG) }

Slide 20

Slide 20 text

ANDROID X

Slide 21

Slide 21 text

ANDROID X - Package refactoring Diivision between APIs that are bundled with the platform and which are static libraries for app developers that work across different versions of Android. android.* vs androidx.* namespaces Old New android.support.** androidx.@ android.databinding.** androidx.databinding.@ android.design.** com.google.android.material.@ android.support.test.** (in a future release) androidx.test.@ Old New android.arch.** androidx.@ android.arch.persistence.room.** androidx.room.@ android.arch.persistence.** androidx.sqlite.@

Slide 22

Slide 22 text

ANDROID X - Migration Per-artifact strict semantic versioning Migration from 28.0.0-alpha1 android.support to androidx-packaged dependencies has two major parts: source refactoring and dependency translation.

Slide 23

Slide 23 text

APP ENGAGEMENT

Slide 24

Slide 24 text

Slices A "slice" is a way to surface your app's UI inside of the Google Assistant as a result of a search Your Actions can appear in the Android launcher, Smart Text Selection, the Google Search app, the Google Assistant, and the Play Store.

Slide 25

Slide 25 text

DISTRIBUTION

Slide 26

Slide 26 text

App Bundle 1. Android App Bundle & Google Play Dynamic Delivery 2. Dynamic features via the Android App Bundle 3. Google Play Console 4. Google Play Instant

Slide 27

Slide 27 text

ANDROID P

Slide 28

Slide 28 text

ANDROID P - Android In Enterprise ● Work profile user interface ○ Switch apps across profiles ○ Programmatically turn work profiles on or off ● Lock down any app to a device Android P also extends the lock task APIs to profile owners of affiliated and non-affiliated users. Follow the steps below to lock an app to the screen: ○ Call DevicePolicyManager.setLockTaskPackages() to whitelist apps for lock task mode. ○ Call ActivityOptions.setLockTaskEnabled() to launch a whitelisted app into lock task m ● Support multiple users on dedicated devices ● Clear package data and remove accounts ● Restrict sharing into a work profile

Slide 29

Slide 29 text

ANDROID P - Power Management ● App Standby Buckets ○ Active ○ Working set ○ Frequent ○ Rare ● Background restrictions ● Battery saver improvements ● Doze

Slide 30

Slide 30 text

Thank you ! Any questions ? Deesha Vora [email protected] @deesharv