At the Google I/O 2018 there were various Android related launches, talks and discussions. Here is one attempt to bring all of the updates under one page for fellow Android Developers to refer and learn.
A set of libraries, tools and architectural guides to help make it quick and easy to build great Android apps.
Brings development tools, components, best / recommended practices, recommended app behaviors and common UI elements together under one roof for developer reference and usage.
Contains 4 major components each of which (and their sub-components) can be used individually.
Cannot be used as a dependency or a library. Is just an umbrella term for all the libraries maintained by Google to make it easier and faster to develop apps.
Components
Foundation - Handles Android device fragmentation efficiently and help writing concise, testable code
The Navigation Architecture Component simplifies the implementation of navigation between destinations in your app (A destination is a specific screen in an app)
By default, the Navigation Architecture Component includes support for Fragments and Activities as destinations, but you can also add support for new types of destinations. A set of destinations compose an app’s “navigation graph.”
Principles:
Focuses on the Activity being an entry point and container, whereas fragments take the center stage for content and navigation between screens.
Abstraction layer for navigation, performs Activity transitions, Fragment Transactions and back stack maintenance seamlessly for you.
Declaring your Navigation graph ahead-of-time so that the system can understand it and execute Navigational code for you.
Requirements:
Android Studio 3.2 - Canary 14+
Implementation:
Create a navigation graph (looks like a Wireframe) within XML / Code and link screens with each other (both forward and backward linking if needed)
Use the NavigationController either
Set a view's onClickListener with Navigation.createNavigateOnClickListener(nextScreenId, args) for navigating when clicked
At the point of navigation, after business logic, call View.findNavController().navigate(R.id.nextScreenId)
Bonus: Interoperability
Hooks up with BottomNavigationView, Toolbar and other top-level navigational views for back navigation, selections and automagic transitions when specifying destinations in Menu resource files.
Hooks up directly with the Manifest Merger so that all Deeplinks / Intent Filters for a given Activity are populated in the Manifest at build time.
Easier testability of navigational logic since NavigationController can be tested in isolation.
Bonus: Safe Args
Compile-time checking for Navigation arguments to simplify argument passing between Navigation components.
Ability to specify argument types and default values if some args are optional.
Internally creates classes to fetch arguments and exposes them as properties via ClassNameArgs.fromBundle(arguments)
The Paging Library makes it easier for you to load data gradually and gracefully within your app's RecyclerView.
Allows you to paginate local results with Room database.
Also allows you to paginate web requests with Retrofit
Code Sample (Non-reactive):
/* In Dao */
@Query("SELECT * FROM users")
funallUsers(): Datasource.Factory<Int,User>
/* In ViewModel */init{
val factory:Datasource.Factory= database.allUsersFactory()
users =LivePagedListBuilder(factory,30).build() //where 30 is the amount of items to load in one page
}
val users:Live<PagedList<User>> = userDao.allUsers()
/* In Activity / Fragment */val adapter =MyAdapter()
viewmodel.users.observe(this){
adapter.submitList(it)
}
/* In Adapter */classMyAdapter():PagedListAdapter<User, UserViewHolder>(
object: DiffUtil.ItemCallback<User>(){
//Override areItemsTheSame and areContentsTheSame
}
){
overridefunonBindViewHolder(holder:UserViewHolder, position:Int){
val user :User?= getItem(position) //User is now nullable
}
}
PagedList.Config can be used to override the page-size ( amount of items to load in one page), initial load size (amount of items to load on the first page), prefetch distance (prefetch distance which defines how far ahead to load) and enable place holders(display null placeholders)
Placeholders when enabled, send nulls to the adapter when data is yet to be successfully pulled and can be rendered to show loading to the user.
Code Sample (Reactive):
/* In ViewModel *///Flowable or Observableval concertList:Flowable<PagedList<Concert>> =RxPagedListBuilder(
concertDao.concertsByDate(),
/* page size */50
).buildFlowable(BackpressureStrategy.LATEST)
/* In activity or fragment */
viewModel.concertList.subscribe({flowableList ->
adapter.submitList(flowableList)
})
Datasources
PositionalDataSource - To be used when user can directly scroll to a particular position in the yet-to-be-loaded list. eg - Contacts app
ItemKeyedDataSource - To be used when your data source holds some kind of ordered key which can help identify the next or previous item to a particular item.
PageKeyedDataSource - To be used when the data returned to be from the server is paginated as pages and the last element of each page points to the next page.
Network Pagination
Consider your local cache (database) as the source of truth.
Whenever you run out of data locally or optionally on first load, ping the server, handle results and insert to database, which in-turn updates the UI.
Use BoundaryCallback to auto trigger network load when the local runs out of data
An Android App Bundle is a new upload format that includes all your app’s compiled code and resources, but defers APK generation and signing to Google Play.
It uses Google Play’s new app serving model, called Dynamic Delivery. It will generate apk based on the user's device configuration such as screen density, CPU architecture, locale etc. Your user downloads only resources required for his/her device.
There will be three apks:
Base APK: This APK contains code and resources that all other split APKs can access and provides the basic functionality of your app.
Configuration APKs: It includes resources for different screen density, CPU architecture, locale etc.
Dynamic feature APKs: These are the APKs that are not required at the install time but it will be downloaded and installed in real-time when the feature is required.
Convert View - Easily convert an existing ViewGroup into a ConstraintLayout or LinearLayout or CoordinatorLayout by right clicking on it in the Layout Editor.
Navigate to included layout - If you have an included layout, clicking on it in the editor will open its hierarchy there itself, instead of having to open it separately.
Additional information to Android Studio to display test content, apply test parameters during development. All parameters are ignored during run time. Ex:
tools:listitem : populate item's layout in a RecyclerView in the editor
tools:itemCount : populate X number of item's in a RecyclerView in the editor
tools:showIn : to show an included layout as it appears in the parent
tools:text : set a probable text to a TextView
tools:textColor - set a probable color to a TextView
Sample Data
Introduced in AS 3.0. It helps you populate data which is not available at the same time. Each time a random value is picked from the sample space.
Creation - Right click on module > New > Sample Data Directory > Right Click on newly created sampledata directory > New > File > {filename}
ConstraintLayout allows you to create large and complex layouts with a flat view hierarchy (no nested view groups). Sometimes referred to as a RelativeLayout on Steroids.
ConstraintLayout 1.0 allowed:
Relative Positioning
Center and Bias Positioning
Group behavior (chains / weights)
Visibility behavior
Aspect Ratio
ConstraintSet
Guidelines
ConstraintLayout 1.1 added, in addition to others, Barriers - position an element relative to a set of elements.
ConstraintLayout 2.0 additions:
Helpers - Elements that help you define constraints and design UIs but are not rendered on the screen at runtime. Ex - Guidelines. Categorized as:
LayoutManipulation - help you build layouts
Post-Layout Manipulation - fly in an element at first launch
Rendering and decorating
Layers
Circular Reveal - Reveal the referenced layout elements in a circular fashion.
Decorators - A put animations on your views. Like a Lava Decoration to reveal elements as blobs. Ex:
Lava
Bottom bar
Constraint State - A separate XML file to define various states in which your constraints can animate.
MotionLayout - A sub-class of ConstraintLayout to support smoother transitions
Support will be added for ConstraintLayout motion in the future
Runs on Pixel Chromebook
No ADB yet
D8 is the default dexer and R8 is the new optimizer and shrinker to improve build speeds as well as replace Proguard
Android Things
��
Android Things is Google's platform to support the development of Internet of Things devices. Which is now in 1.0 production ready version. This section has all Android Things related video what's new, updates and best practices
What's New ? : Learn more about the breadth of hardware reference designs, the operating system, building apps, device management, and support from chip vendors.
Device Provisioning and Authentication : This talk will discuss how to support authentication, provisioning from a mobile device, and device attestation.
Android Things Console: Android Things provides a powerful developer Console that manages your device deployments. Learn more about how to take your APKs and hardware configurations, and build them into system images, which can then be rolled out to all of your devices via over-the-air updates.
System On Modules: How to create your own SOM carrier boards, including creating the design from scratch, working with a fabrication company, assembly and testing, and taking it all the way to production.
Build Real Consumer Devices : This talk will walk through the journey of building consumer devices like Smart Displays using Android Things
Build effective OEM-level apps : As an Android Things OEM. How should you structure your code? Should you use activities or services? Should the code be running in the foreground or the background? Do you package all the code into one APK, or split components up into modules? Find answers to all of these questions and more with best practices for building OEM-level apps.
Contribution
Looking for a lot of contributions!Kindly refer the Contribution guidelines for smoother contributions.
问题分析 在下载文件时,报的异常如下所示:FileNotFoundException 10-24 11:16:44.446 3936 7905 W System.err: java.io.FileNotFoundException: /sdcard/MDS/Jellyfish.jpg: open failed: ENOENT (No such file or directory)
10-24