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

Android Latest Version Features & Architecture ...

Android Latest Version Features & Architecture Components

The Presentation highlights all the latest features in Android Oreo and P along with deep dive into architecture components.

Gaurav Bhatnagar

August 01, 2018
Tweet

More Decks by Gaurav Bhatnagar

Other Decks in Technology

Transcript

  1. Agenda • What’s new in Android P • New features

    integrated in Android 8.0 & 8.1 (Oreo) • Android Jetpack • Details about Architecture Components • Lifecycle Component • LiveData • ViewModel • Room • Paging • WorkManager & Navigation Components
  2. What’s new in Android P • Slices • Biometric Prompt.

    • Foreground Service Permission + Improvements on Background processing using Priority Buckets • HTTPS Required by default. • Notification Improvements • Display Cutouts. • AppComponentFactory. • WebView Improvements Source : https://developer.android.com/preview/
  3. Slices • A “slice” is a mechanism to show your

    app’s highlight inside of Google Search/Assistant. • Here the actual UI is rendered by another app. • Slice is built on the interaction between provider app and the host app. Source : https://goo.gl/ya9HpA
  4. BiometricPrompt • The FingerprintManager API has been deprecated and replaced

    with BiometricPrompt. • It provides stock UI around fingerprint scanning. • BiometricPrompt can handle other forms of biometric authentication such as face scanning or iris scanning.
  5. Priority Buckets • Active • Working Set • Frequent •

    Rare • Never Source : https://goo.gl/9d4tys
  6. App Security Improvements • From the second half of 2018

    Google Play will require new apps & app updates target the recent Android API level. • Aug 2018 : New apps required to target API level 26 (Android 8.0) or higher • November 2018 : Updates to existing apps required to target API level 26 or higher. • 2019 onwards : Each year the targetSdkVersion requirement will advance.
  7. Android Oreo • Notification Dots & Channels • Autofill Framework.

    • Adaptive Icons • Background Limitations. • Java 8 language APIs • Picture-in-picture • Downloadable fonts. • Autosizing TextView • Neural Networks API and many more. Source : https://developer.android.com/about/versions/oreo/
  8. Notification Channels & Badges • Objectives • Visual Consistency •

    Expand Animation. • Providing more control to the end users. • Avoiding all the spam notifications. • Implementations • To target Oreo need to implement notification channels and incorporate badges. Source :https://goo.gl/ZZLaaD
  9. Background Processing Limitations • Improve RAM / Battery performance. •

    Restricting Background processes for different applications • Services run freely in foreground • Background services are stopped when idle. • Bound services are not affected. • Limitations on Background Location Updates • When in Background apps to receive location updates only a few times each hour.
  10. Android Jetpack Components • A collection of libraries that are

    individually adoptable and built to work together to make android developers more productive. • Accelerate Development • Eliminates boilerplate code. • Build high quality apps with no memory leaks and fewer crashes with backward compatibility integrated.
  11. Need of Architecture Components • Achieve Separation of Concerns •

    Always Drive UI from the Model. • Try to implement the architecture which is robust , testable and easily maintainable. • Now it is 1.x (Stable) out of its alpha and beta stage.
  12. Life-Cycle Aware Components • Components that can automatically adjust their

    behaviour based on the current lifecycle state of an activity or fragment. • They are core to how android framework works and our app must respect them. • Using the LifecycleOwner Interface and LifecycleObserver in an optimized manner. • For e.g. If we need to implement the location listener for live tracking in our application we can make the location listener implement LifecycleObserver and initialize in our UI component’s (Activity) onCreate().
  13. Using the LifecycleOwner & LifecycleObserver class MyActivity extends AppCompatActivity {

    private MyLocationListener myLocationListener; public void onCreate(...) { myLocationListener = new MyLocationListener(this, getLifecycle(), location -> { // update UI }); Util.checkUserStatus(result -> { if (result) { myLocationListener.enable(); } }); } } class MyLocationListener implements LifecycleObserver { private boolean enabled = false; public MyLocationListener(Context context, Lifecycle lifecycle, Callback callback) { ... } @OnLifecycleEvent(Lifecycle.Event.ON_START) void start() { if (enabled) { // connect } } public void enable() { enabled = true; if (lifecycle.getCurrentState().isAtLeast(STARTED)) { // connect if not connected } } @OnLifecycleEvent(Lifecycle.Event.ON_STOP) void stop() { // disconnect if connected } } Source : https://developer.android.com/topic/libraries/architecture/lifecycle
  14. Best Practices (Handling Lifecycle) • Keeping the UI as lean

    as possible. • Since the UI will be dumb, it will be easier to test using Instrumentation tests. • Components that implement LifecycleObserver work seamlessly with components that implement LifecycleOwner because an owner can provide a lifecycle, which an observer can register to watch. • Using this in video buffering, network connectivity , animated drawable etc.
  15. LiveData • It is an observable data holder class that

    notifies views when the underlying model changes. The USP is that it is lifecycle aware. • The awareness makes LiveData quite invaluable as it makes sure that UI components are updated only in an active lifecycle state. Source : https://goo.gl/ff4NK9
  16. Advantages of LiveData • Ensure that Lean UI matches data

    layer state. • Minimizes memory leaks. • Reduces the crash rates and improves stability. • Proper Configuration Changes. • No more manual life-cycle handling. • Always up-to date data. • Sharing Source : https://goo.gl/ff4NK9
  17. ViewModel • It is designed to hold and manage UI-related

    data in a life-cycle conscious way. This allows data to survive configuration changes such as screen rotations or device language modifications. • A ViewModel outlives the specific Activity or Fragment instances. • A ViewModel will stay in memory until the Lifecycle it’s scoped to goes away permanently – in the case of an Activity, once it finishes; in the case of a Fragment, once it’s detached. • It shouldn’t reference any Views directly inside of it or hold reference to a context. This can cause memory leaks. • ViewModelProvider instance is tied to either an Activity(AppCompatActivity) or Fragment.
  18. Room (Persistence Library) • Provides an abstraction layer over SQLite

    Database. • Optimizes database access while harnessing full power of SQLite. • It serves as app’s single source of truth which assists in providing offline first experience to end users.
  19. Room architecture Diagram • There are three major components in

    Room: • Entity • DAO (Data Access Objects) • Database Source : https://goo.gl/MEbi8j
  20. References • https://developer.android.com/jetpack/docs/guide • https://developer.android.com/topic/libraries/architecture/ • https://developer.android.com/topic/libraries/architecture/lifecycle • https://developer.android.com/topic/libraries/architecture/viewmodel •

    https://medium.com/google-developers/viewmodels-and-livedata-patterns-antipatterns-21efaef74a54 • https://riggaroo.co.za/android-architecture-components-looking-viewmodels-part-2/ • https://medium.com/google-developers/viewmodels-a-simple-example-ed5ac416317e • https://developer.android.com/jetpack/ • https://android-developers.googleblog.com/2018/05/use-android-jetpack-to-accelerate-your.html