Android Jetpack Weekly #7
Review of the most interesting updates in Android Jetpack libraries
If you now Russian and want to know more about Android development you can subscribe to Android Broadcast Telegram Channel
Update in AndroidX for period September 1–8 2019. The week was very rich and many stable versions were released:
Fragment
1.1.0 (compare to 1.0.0)
FragmentScenario
class for testingFragment
in isolation- Now you can set a
FragmentFractory
on aFragmentManager
to override creation of fragment. Now default constructor isn’t required forFragment
. Welcome injection into constructors with Dagger 2! - Kotlin Property Delegates for ViewModels:
by viewModels()
andby activityViewModels()
- Max Lifecycle state for a
Fragment
by callingsetMaxLifecycle()
on aFragmentTransaction
. It allows setting a ceiling for the state of an active fragment in thisFragmentManager
.
The new API replace deprecatedsetUserVisibleHint()
. ViewPager 1 added support of Max Lifecycle inFragmentPagerAdapter
andFragmentStatePagerAdapter
in constructors. - Set layout id for
Fragment
andFragmentActivity
via new constructors. No need to overrideFragment.onCreateView()
or callActivity.sentContentView()
- Postpone
Fragment
transaction with a timeout using postponeEnterTransition().
1.2.0-alpha03 (compare to 1.2.0-alpha02)
- API changes
- Bug fixes
Preference
1.1.0
PreferenceFragment
and other classes using framework Fragments have been deprecated; you should usePreferenceFragmentCompat
and other *compat classes instead- You can now set a
SummaryProvider
on a Preference to dynamically configure its summary (second text) whenever the Preference is updated or becomes visible to the user. See the guide for more information. - Added
EditTextPreference.OnBindEditTextListener
interface that allows customizing theEditText
displayed in the corresponding dialog after the dialog has been bound. This is a direct replacement for using attributes such asandroid:inputType
directly on theEditTextPreference
, which is not supported in the AndroidX library. See the guide for more information. - Added possibility to show a context menu when long pressing on the Preference that allows copying the summary of the Preference. Use
Preference.setCopyingEnabled()
to enable/disable that. - Updated
SeekBarPreference
styling to match Material specifications: the value label is now hidden by default; the value label now updates while the SeekBar is being dragged, instead of when it is released; you should avoid setting a summary on aSeekBarPreference
- SeekBarPreference: Added support for continuous updates, allowing the SeekBar to update its saved value
- A large number of bug fixes, style updates, API level compatibility fixes, and general QOL (quality of life) improvements.
Lifecycle
2.1.0 (compare to 2.0.0)
- Added
LifecycleEventObserver
for the cases when a stream of lifecycle events is needed. UseLifcecycle.addObserver()
to register a listener. - Added ktx extensions for
LiveData.observe
methods andTransformations.*
methods. - Added
Transformations.distinctUntilChanged
, which creates a newLiveData
object that does not emit a value until the sourceLiveData
value has been changed. - Added coroutine support in ViewModels by adding the extension property
ViewModel.viewModelScope
. The scope is bound toDispatchers.Main.immediate
2.2.0-alpha04
lifecycleScope
,whenCreated
,whenStarted
,whenResumed
,viewModelScope
, and the underlying implementation ofLiveData
now useDispatchers.Main.immediate
instead ofDispatchers.Main
Activity
1.0.0
- New
ComponentActivity
servers as the new base class forFragmentActivity
- Kotlin Property Delegates for ViewModels:
by viewModels()
- As a composable alternative to overriding
onBackPressed()
, you can now register aOnBackPressedCallback
from anyLifecycleOwner
(such as a Fragment) to intercept system back button events. onRetainCustomNonConfigurationInstance()
and the relatedgetLastCustomNonConfigurationInstance()
APIs have been deprecated. UseViewModel
instead.
1.1.0-alpha03 (compare to 1.1.0-alpha02)
- Dependencies updates
- Bug fixes
AppCompat
1.1.0 (compare to 1.0.0)
- Dark Mode Improvements:
MODE_NIGHT_AUTO_BATTERY
was replaced withMODE_NIGHT_AUTO
AppCompatActivity
now transitively extends fromComponentActivity
- Set layout id for
AppComponentActivity
via new constructors. No need to callActivity.sentContentView()
SavedState
1.0.0
This is a set of APIs that allow developers to plugin components into the restore / saveInstanceState process. That API provides a single way to how to save the state of any class without keeping a direct reference to it.
CameraX
Camera2 & Core 1.0.0-alpha05
- APIs refactoring
- Added
CameraControl
API w/Tap-to-Focus APIs - Enforce calling some API methods on the Main (UI) thread
- API improvements
- Bug fixes
Core
1.1.0
- Updated accessibility APIs to match the Android 10 platform accessibility APIs
- Added improvements to Nested Scrolling; see
NestedScrollingChild3
andNestedScrollingParent3
. - This library no longer depends on the
androidx.collection
dependency as part of its API - Worked around an IPC compatibility issue caused by refactor to androidx
- Added a variety of fixes for AppCompat DayNight
Media
1.1.0
AudioAttributesCompat
was added
Media2
Media2 is the next generation of following Media APIs: MediaSession
, MediaController
, MediaBrowser
, MediaBrowserService
, VideoView
, and MediaControlView
.
1.0.0
- Base on ExoPlayer
- Support of custom layout in MediaSessions
- Better look and feel
- New possibilities compare to original Media API
MediaRouter
1.1.0
Dynamic group support was added:
- Allows users to add or remove route devices dynamically.
- To enable a dynamic group, call
MediaRouteButton.enableDynamicGroup()
; the app shows a new dialog for the dynamic group - The installed
MediaRouteProvider
should also support dynamic group to actually enable the functionality.
Navigation
2.1.0
- Scoping ViewModels to a navigation graph: You can now create ViewModels that are scoped at the navigation graph level using the
by navGraphViewModels()
property delegate for Kotlin users or by using theNavController.getViewModelStoreOwner()
. See Share UI-related data between destinations. - Dialog destinations: You can now create
<dialog>
destinations that will show aDialogFragment
when younavigate
to them.NavHostFragment
supports dialog destinations by default. See Create a destination from a DialogFragment. - Navigating by Uri: You can now
navigate
using aUri
, which uses the<deepLink>
you’ve added to a destination to navigate there. It helps to organizae navigation in multimodule projects. See Navigate using Uri. - NavHostController: APIs used specifically for constructing a custom
NavHost
have been moved toNavHostController
, allowing implementations to connect theirNavController
to the hostingLifecycleOwner
,OnBackPressedDispatcher
, andViewModelStore
.
2.2.0-alpha02
- Deep links with query parameters now support reordered query parameters: arguments that have a default value or are nullable are now optional when matching deep links.
- You can now call
NavController.getBackStackEntry()
, passing in the ID of a destination or navigation graph on the back stack. The returnedNavBackStackEntry
provides a Navigation-drivenLifecycleOwner
,ViewModelStoreOwner
(the same returned byNavController.getViewModelStoreOwner()
), andSavedStateRegistryOwner
, in addition to providing the arguments used to start that destination. - Bug fixes
ShareTarget
1.0.0-beta01
VectorDrawable
1.1.0 (since 1.0.0)
fillType
is now supported inClipPath
- Tinting is now supported using
ColorStateLists
defined with theme attrs inVectorDrawableCompat
- Bug fixes
WebKit
1.1.0-beta01
- New
InternalStoragePathHandler
inWebViewAssetLoader
to load files from the app's data directory. - Small API changes
- Bug fixe