[MUSIC PLAYING]
CHET HAASE: Hi, and welcome to the first-ever "Now in Android"
filmed in the new, and hopefully very temporary, home studio
that I have setup.
So a lot of things happened in the last two or three weeks
since I did another one of these, so let's
just get rolling on the.
First of all, Android 11 Developer Preview 2 came out.
So we talked about this in the last "Now in Android,"
and then in the meantime, Developer Preview 2 launched.
So briefly, some of the things that are either
new in there or touched-up since the first preview came out
include one of my favorite features
in this or many releases, which is IME animation control.
So developers have been asking us
for this feature for a long time.
And frankly, we internally also wanted
this, where when you need the keyboard on the screen,
and then the keyboard nicely animates up,
but your app does not-- your app snaps.
It is given a new screen size to adhere to
and just snaps into the new format,
and this is discontinuous behavior.
It's something that users would prefer didn't happen,
and developers certainly prefer that they
had more control over it.
And now you do have that control in two ways.
So first of all, there are callbacks.
There's a listener that you can register and get callbacks
to find out when the IME is animating in,
you can find out what position and size
it has so that you can react to that
and then animate your own app along the way.
Or you can actually control the IME animation directly.
So two different APIs to tune into, so check those out.
There are, obviously, a lot of other features in there
that aren't just about my favorite feature.
For example, the NDK image decoder.
So this adds capabilities that are currently
in the Java programming language APIs at the SDK level,
but maybe you didn't have easy access
to those from your native code that you were using
So if you're a native code developer,
you either had to up-level--
jump through JNI and call these things up at the higher level--
or even worse, from an APK size standpoint,
you had to bundle somebody else's library in order
to decode images.
Now you can use the NDK image decoder directly
to decode all kinds of images, like JPEG, PNG, GIF--
"Jif"?
G-I-F-- WebP, and HEIF--
"Heef", "Hife"-- however you pronounce that.
Let's pronounce it "Jif."
So there's an NDK guide on using this thing.
There's also a sample.
Check out texture.cpp in that sample.
Links, as always-- go check out the article on Medium.
They have links to all this stuff.
Another feature that's interesting
is nullability in Android 11.
So Kotlin has this great feature where you can use a language
feature to declare whether variables
are nullable or nonnull, which is fantastic.
But what do you do for the Java APIs?
Well, there are annotations that can be used in a similar way,
and we have, over time, been adding annotations to the APIs
at the Java programming language level,
and we have added more of those in this release.
And we've also enhanced some of those annotations.
So there's a couple annotations, like @RecentlyNullable
or @RecentlyNonNull, which have the capability
of those built-in annotations, but they only
issue a warning at build time.
But we've upgraded some of those to be
@Nullable and @NonNull annotations, which
means you're going to get an error at build time.
And then we've also added more for APIs that weren't covered
through those annotations.
Already, we've added more @RecentlyNullable and
@RecentlyNonNull annotations.
So all of that's good, but there's
even more in the DP 2 release that's worth checking.
First of all, for foldable devices,
there is a hinge angle sensor.
NNAPI added a hard-swish op, which obviously
builds upon the swish activation functions, which
I mention mainly because I just think
these names are really cool.
Also, there's an intense academic article
that covers the background in why swish activation
functions are really more powerful, much faster
for doing more accurate training.
So definitely check out the article
and NNAPI for those changes.
Also, microphone and camera are now
taking on the same responsibility
that we had for location in Android 10,
which is if you want to be used in a foreground service,
then you need to declare a foreground service-type
attribute in your manifest.
We actually discussed this in episode 133 of the "ADP"
podcast, called "Power Play."
So if you want to hear from the engineering team
on some of this stuff and other related things,
check that out, as well.
Another interesting Android 11 feature is the ability to tune
into the variable refresh rate capability on devices
that support it, and also the emulator now
supports cameras that are both front- and back-facing.
So the whole reason that we do these preview
releases, actually push the release out there way, way, way
before it's ready, is to give you a chance to react to it,
to actually test your app.
And make sure that, a, your app is working correctly,
and b, our release is working correctly for your app.
So do take the opportunity.
Test your app out.
Make sure that it's working.
Fix the things that need to be fixed, or tell us.
There are feedback forms on the DP 2
or the Android 11 Preview site for you
to tell us what is not working correctly
so that we can actually get things in the proper shape
before we ship the final release.
Speaking of release, there were obviously
a few AndroidX releases, because there always are.
First and foremost, CameraX is now beta.
So this came out some time ago in alpha form,
and it's been evolving through those alpha releases
ever since.
But now it's out in beta.
So if you were waiting for the API to be stable,
this would be your time.
The team is still working on fixing issues going up
to the full release, obviously.
But in the meantime, the API will remain stable,
so you can depend on that a bit more.
Some of the things that are interesting
in the beta release, compared to when it initially came out
in alpha, includes explicit camera initialization
with ProcessCameraProvider.
You can also choose which camera--
the front or the back-- that should be used
for any particular use case.
And you can also get more information and more control
over specific camera features, like zoom and focus.
Another release that's worth checking out
in the camera space is actually an alpha release,
which is Camera View.
But this has various utilities and facilities
that are specific to use of camera functionality
within a View hierarchy.
So worth checking out because this
might be some of the ease of use stuff that you are looking for,
and that's now available in alpha for you to play with.
On the stable side for AndroidX, a few things
came out that were mostly bug fix releases.
Fragment 1.2.3.
Paging 2.1.2-- I mention this specifically because 2.1.1
had a weird build, and configuration,
and push and release issue where some of the APIs
came out a little bit too early and they weren't quite done
yet.
We basically exposed APIs before they were ready.
So if you're trying to use 2.1.1, upgrade.
Use 2.1.2 now.
That's going to be a better choice.
Room 2.2.5 came out, another bug fix release.
Webkit 1.2.0, which includes the ForceDark
API to control rendering web views in dark mode.
And finally, WorkManager-- they get bonus points
because they released both 2.3.3.
and 2.3.4 since the last issue of "Now in Android."
On the alpha side of AndroidX, there's
one particular one that's worth checking out,
which is Activity 1.2.0.
This is now in alpha 2.
The new thing in this particular alpha release is the support
for ActivityResultRegistry, which allows you to handle
startActivityForResult() and onActivityResult(),
as well as requestPermissions() and
onRequestPermissionsResult().
It allows you to handle these flows without actually needing
to override the appropriate methods in Activity
and Fragments, so a lot easier to use.
If you use that version, you should probably also upgrade
to use Fragment 1.3.0, which is also
in an alpha 2 release at this point.
Many, many articles came out since last we talked.
First of all, Nick Butcher released the next
in a series of Android styling articles,
and he did this one, "Themes Overlays."
This one talks about using theme overlays
to set just a small subset of attributes
that you might want to set that then overlay--
you see why that word is used--
the other attributes that are being
set by the dominant theme in the hierarchy.
App bundle testing is an area that people are interested in,
obviously.
Ben Weiss wrote an article that talks about how
to do that with app bundles.
So previously, it used to be straightforward.
You build your APK, and then you'd
give the APK to your tester or your testing team,
and away they go.
They test their stuff and everything's good.
In the app underworld, you build a thing,
which is not the APK that anyone would download.
So what's the flow?
What's the process for your testers to actually get and use
the real bits that they should be
testing if we have this indirection through the Play
Store?
Well, now we provide a testing flow
through that indirection process.
So now, there is a way for your testers
to log on and get APKs based on the app bundle that you built.
And his article goes into details on that.
There's also another new feature offered that he goes into,
depth on, in the article that allows
people to get historical versions of your app.
So for example, you can now debug something
that is specific to an older version
by logging on and getting that particular APK,
and away you go.
And it also allows you to test the in-app update flow.
You can get that older version, make sure
that the in-app update works to a more recent version.
There's also an article on enums using
the when statement in Kotlin, and also the use of R8.
This is an article that I posted that's based on a talk
that I did with Romain Guy at KotlinConf.
It was called Kotlin Under the Covers?
Kotlin Uncovered-- that was the one--
where we talked about all kinds of language features
and how some of them are improved through optimizations
in the R8 compiler.
This one is about the specific optimization
that R8 can provide when you're using enums inside of a switch
or a when statement, and some of the overhead
that that sometimes implies.
There's also "The suspend modifier."
This is an article posted by Manuel Vivo, who
explains how the Kotlin compiler transforms
code routines under the hood.
So how does this stuff actually work?
Yacine posted article on storage.
So we made a lot of changes to Scope Storage in Android 10,
and this article goes into depth in a lot of those changes.
And it also describes some of the changes
that we made in Android 11, as well
Kotlin coroutines-- there's actually
a three-part series posted by Manuel Vivo and Florina
Muntenescu on cancelation and exception.
So part one does a quick overview of code routines--
in particular, describing things like CoroutineScope, Job,
and CoroutineContext.
Part two covers coroutine cancelation.
So it talks about how to cancel specific Jobs, as well
as entire CoroutineScopes.
And it also discusses how cancelation
needs to be cooperative.
So just because you cancel a coroutine
doesn't mean that that thing is going
to stop processing the code that it is in the middle of doing
in the actual coroutine.
So this article talks about some of those details.
And then part three finally wraps up the series
by discussing what to do when things don't really
go as you hoped they would.
So how do you actually handle exceptions
in your coroutine code?
So for example, when there is an exception thrown
by a coroutine, it will, by default,
propagate that exception up and could
cause the cancelation of all coroutines
in your app-- or sorry, in the coroutine scope that it's in,
cause all of them to be canceled,
which is maybe not what you wanted.
So how do you then change that behavior
and focus or localize the exception
to just where it should be, instead?
There were a few videos that came
online in this last little while, as well, that are worth
talking about.
First, accessibility.
Shailen Tuli and Lyla Fujiwara posted a video
about accessibility, and the simple things
that you can do, as a developer, to make your application more
accessible and useful to everybody.
This is one of the longer-form videos--
I think Nick Butcher did an earlier one a few weeks ago--
where we basically take content intended for a conference crowd
and we boil it down and optimize it into a shorter talk,
but a longer video, that covers all the details that you
need into deeper topics, like for example, accessibility.
"Kotlin Vocabulary" is an ongoing series that a few of us
have been participating in that Florina is running,
and there were three more episodes of "Kotlin Vocabulary"
that came out in video form.
First of all, Manuel posted "Suspend Functions,"
which is basically the video version of the article
that I mentioned earlier, talking
about how all this stuff works.
Florina posted "Collections and sequences,"
which talks about when to use the Kotlin collection
APIs for eager evaluation versus using Kotlin sequences
for lazy evaluation.
And then finally, I posted a video version
of the article I talked about earlier on the use of enums,
and when or switch statements, and R8.
So that's called "D8, R8, and enums,"
so you can check out that video if you'd rather consume
the video than the article.
Also, Google for Game.
So there's this great game developer conference
called GDC, where we were really looking forward to going.
And due to realities, that did not happen this year.
So we could not go there.
However, we took all of the content
that we were going to talk about there, including some
of the new capabilities that we've just come out
with for game developers, and we put it online
in a couple of different ways.
First of all, there's an article that
covers all of the details in much more detail
that I'm doing here.
But there's also a playlist on YouTube
where we posted both the keynote that we were going
to have at the conference, as well as
technical sessions that go way into detail
in all of this stuff.
So there were a bunch of new things that we're offering
lately that are worth checking out for game developers,
such as native profiling capabilities--
these are now added to Android Studio's Trace tool--
and the support for native debug symbols in the Android Vitals
Console.
So now you can upload those symbols
so you can get more information when there are crashes out
in the field.
And also, easier access to Google
APIs for Unity developers.
You can also sign up for previews
to check out some of the stuff that's currently
in development, including a game development
extension for Visual Studio.
In case that's your flow and process for developing
cross-platform games, we've made it easier
for you to then develop Android content in that same tool.
And you can also sign up for the preview for a new Android GPU
inspection tool.
As I said, there's an article on all this stuff
and the YouTube playlist with lots and lots of content
there, so check those out.
And then finally, "ADP" podcast.
We've had two podcasts go live since the last episode.
Episode 133, "Power Play"--
I mentioned this one earlier.
I talked with Amith Yamasani, Makoto Onuki, and Kewku Adams,
and they're all three from the framework engineering team.
And we talked all about power--
things like the heuristics that the system use when it's
deciding which tasks to kill.
If your application launches and it needs more memory
than is available, well, the system
has to do something about it.
So how does it make that decision?
We also talked about doze mode, which
is sort of an ongoing effort from the engineering team,
in general, about how to save battery on the system overall.
We talked about TrimMemory requests.
So the system is going to send out
a call to the whole system saying,
hey, it'd be a great time to save on memory
or else I'm going to start killing applications.
So how does that work?
We talked about how JobScheduler works.
JobScheduler is an API at the framework level.
We recommend that people use--
sorry.
We recommend that people use WorkManager, actually,
as a higher-level API, which then uses JobScheduler
under the hood as well as some other facilities
to schedule that work.
We also talked about AppStandby buckets.
We talked about foreground services.
So lots of things in that podcast to check out.
And then finally, episode 134 was just launched last week,
called "All Work and No Play."
I talked with Sumir Kataria and Rahul Ravikumar
from the Android Toolkit team about WorkManager.
We've had one or both of them on the podcast previously,
and this time, we give an overview
of how all of this stuff works, as well as
lessons they've learned along the way, as well as some
of the new features that have come
online since the last time we talked to them.
That is it for this time.
Thanks for joining me on the video or on the podcast.
Please check out the article for all the links.
And if you like the video, go ahead and like, and share,
and subscribe to the Android Developers channel on YouTube.
Thanks.
[MUSIC PLAYING]