Office Hours — Today, December 10

Tuesday, December 8

Mark M.
has entered the room
Mark M.
turned on guest access
Dec 10
4:00 PM
Michael W.
has entered the room
Mark M.
hello, Michael!
how can I help you today?
Michael W.
Hi Mark
In the book chapter Divider on RecyclerView
Drawable divider = getResources().getDrawable(R.drawable.item_divider);
Saw getDrawable deprecated
Mark M.
IIRC, there is a two-parameter version added in Android 5.0, taking a theme ID as the second parameter
that's not available in older versions of Android
Michael W.
I see.. So what's should be?
Mark M.
what I have is perfectly fine for the purposes of that app
"deprecated" means "there's something else that we think that you should consider using"
most stuff that is deprecated continues to work fine
4:05 PM
Michael W.
great..
Another stuff, I'm creating an activity, with Toolbar, and some fragments inside
I have created a fragment transition, and worked on the 'content' which is the one inside Fragment Layout
I want to make the Toolbar also animating, for example the title change
But still not have any idea how to do that
Mark M.
I doubt that it is possible in any supported fashion
Toolbar does not expose its internal workings
Michael W.
I'm trying to put the toolbar inside the fragment, is it a good idea?
Mark M.
um, I cannot really answer that
Toolbar is designed to go wherever you want it
Bob S.
has entered the room
Michael W.
But then I will have a nested fragment.. Is it nested fragment recommended or not?
Mark M.
using a Toolbar does not require nested fragments
using a Toolbar does not require any fragments at all, for that matter
(BTW, Bob, I will be with you shortly!)
that being said, I am not a fan of nested fragments
I will go out of my way to avoid them
Michael W.
Agree.. Anyway I will let Bob to raise question first
Bob S.
Reading discussions on SO, I see that many people are using the Genymotion emulator. What are your thoughts on the adequacy of the stock emulators and the benefits of using one of the alternatives?
Mark M.
I have never used Genymotion, due to issues that I have had with their license agreement
4:10 PM
Bob S.
Do you find that the stock emulators meet most of your needs?
Mark M.
I tend to use hardware more than emulators, but I have more hardware than does your average Android developer
Bob S.
Okay, thanks.
Mark M.
based on comments that I have seen, my sense is that Genymotion is an improvement over the stock emulators, and neither is as good as hardware
at least, when you have hardware for the scenario that you're trying to test
now, the Android Studio 2.0 emulator looked slick in the demos shown at the Android Developer Summit a few weeks ago
so they're obviously giving it a bit of attention
let me take another question from Michael, and I will be back with you in a bit
Michael: your turn! do you have another question?
4:15 PM
Mark M.
OK, if either of you have a question, go right ahead
Michael W.
Yes, I've just had a nested fragment because I'm trying to create master-detail app in 1 activity
Bob S.
I've been learning more about TaskStackBuilder. In the docs, I've only seen it used with Notifications. Are you aware of other situations where TaskStackBuilder can be put to good use?
Michael W.
And also put ViewPager
Mark M.
Michael: remember that ViewPager does not necessarily require fragments, and neither does master-detail
fragments are typical ways of implementing those, but not the only way
Bob: I think it gets used for up navigation
Michael W.
I thought that ViewPager only works on Fragment.. Even if combining with tab layout also?
Mark M.
ViewPager uses a PagerAdapter
the PagerAdapter base class only knows about Views
the two concrete implementations of PagerAdapter in the support libraries use fragments
but PagerAdapter itself does not
in the book, I have at least one example of a fragment-less PagerAdapter
Michael W.
in the method public Fragment getItem, it should return Fragment right?
Mark M.
that is FragmentPagerAdapter or FragmentStatePagerAdapter that you are referring to
you do not have to use those implementations of PagerAdapter
Michael W.
ok, thanks, Mark
4:20 PM
Michael W.
Btw, still not found the fragment-less PagerAdapter on the book
Mark M.
Michael W.
Thanks, Mark
Mark M.
see page 763 of Version 6.9 of the book
they are covered in a discussion of how to have more than one page visible in a ViewPager, as one way of making better use of larger screen sizes
Michael W.
Found it, thanks
Regarding the setHasOptionsMenu, is it only useful for modifying menu from fragment?
4:25 PM
Mark M.
it is how a fragment indicates that wants to participate in the action bar
if a fragment does not need to do that, do not call setHasOptionsMenu(true)
(BTW, Bob, if you have other questions, chime in!)
Michael W.
Thanks Mark, just try that
Bob S.
I was recently trying to answer a question on SO that involved background service state, process management, and such. It eventually become clear the user's device was running Xiaomi MIUI and much of what I understood to be the standard Android behavior didn't apply. How far has MIUI diverged from Android? Is it even correct to still call it Android?
4:30 PM
Mark M.
well, AFAIK, Xiaomi MIUI devices are not Google Play ecosystem devices, and therefore do not have to pass the Compatibility Test Suite
in theory, device manufacturers will aim to be close, if they want third-party developers to ship apps on their devices
so, Amazon was worse early on, but has been better in the second and subsequent generations of their Fire devices
in terms of Xiaomi specifically, I haven't picked up one of their devices to try it out, though I'm looking to do so
Bob S.
Got it, thanks.
Mark M.
it wouldn't surprise me if they have tinkered more than average
but I can't cite specific things where they have departed, as I lack direct experience
Michael W.
I have created a RecyclerView with a set of data (some fields, include an image). Each time the activity started it gathered from the server and put into the list of Model.
But when the app close and reopened, it's again download every data, including the images. How to manage this thing?
Mark M.
what exactly do you mean by "close and reopened"?
4:35 PM
Michael W.
close the app and reopen the app
Mark M.
you don't really "close the app" in Android
so, what exactly do you mean by "close the app"?
do you mean "press the BACK button to destroy the foreground activity"?
Michael W.
yes
Mark M.
you are welcome to maintain some process-level data cache, typically in the form of a singleton
your process is not immediately terminated when the user destroys your last foreground activity
and so, if the user returns to your app fairly quickly, your cache can speed up presenting data to the user again
however, you need to take care, as any singleton amounts to an intentional memory leak
you do not want to start causing yourself OutOfMemoryErrors
Michael W.
So the singleton will still exist unless the user destroy the app from the settings?
Mark M.
no, the singleton will exist until the process gets terminated
that can happen at any moment while your app is in the background
once the user presses BACK or HOME, and you are no longer in the foreground, your process is eligible to be terminated, to free up system RAM for other apps
that may happen in milliseconds, seconds, minutes, or hours
it all depends on how much system RAM the device has, how busy the device is, etc.
Michael W.
should I add another 'layer' like SQLite?
Mark M.
you are certainly welcome to persist data to local files
that could be in the form of a second-level cache
or it could be that you work primarily with the local data, synchronizing data with your server as needed
Michael W.
Since now I'm just creating singleton and save the data into the server directly
4:40 PM
Mark M.
BTW, Bob, Google just posted an article about that new Android Studio 2.0 emulator: android-developers.blogspot.com/2015/12/android-studio-20-preview-android.html
Michael W.
okay thanks Mark
Bob S.
Great! I'll take a look.
Michael W.
Which one is most appropiate for sync list of data: Android Async vs OKHttp?
4:45 PM
Mark M.
either should be fine
I tend to use OkHttp
Michael W.
Is there any pro cons?
Mark M.
I like OkHttp's API better
it also dovetails nicely with Retrofit and Picasso
I'm not sure if AndroidAsync has SPDY or HTTP/2 support
Bob S.
This is probably not a good question for a chat session, but I'll ask anyway: I'm still looking at Android architecture diagrams to develop a clear picture of what is in firmware and what gets pulled in from the SDK, particularly the Java libraries. Any tips? Pointers to docs?
Mark M.
Bob: you might try books on Android internals, like Karim Yaghmour's
Michael W.
Will try that
Mark M.
the only things in the "SDK" that become part of your APK are the support libraries
any Java class that doesn't begin with android.support. is only in the SDK in stub form, with the real implementation coming from firmware-supplied code, loaded into the zygote
where the zygote is the master SDK app process that all SDK apps get forked off of
now, if your concern is what happens directly in your process versus other processes, or what happens in Java code versus native callouts, that's another matter
books on the internals probably get into that somewhat, particularly on the IPC side
Michael W.
I'm interested with the size of the APK, so if we use the non-android.support one it will be less size in SDK?
4:50 PM
Mark M.
Michael: any code you add to your app makes your app bigger, whether that code is yours or comes from a library
Michael W.
So if I'm targeting >15 better to use non-android.support?
Bob S.
That helps. I do have some understanding of the numerous "system services" and the Binder interfaces to them.
Michael W.
Sorry, I mean >=15
Mark M.
MichaelL: that is a controversial question
using the support libraries, at least to some extent, is nearly unavoidable
the less you use, the better ProGuard can strip out the unused stuff and minimize their impact
if you are really asking "is it better to not use AppCompatActivity?"... that's where the controversy comes in
I am not a fan of appcompat-v7
that's less an issue of size and more an issue of the way appcompat-v7 is implemented and concerns over long-term stability
however, I am in the minority in this opinion
which isn't the first unpopular opinion that I have held, nor will it be the last :-)
using appcompat-v7 and AppCompatActivity is the conventional choice today
I just happen to sneer in the general direction of convention :-)
Michael W.
thanks for the good and honest explanation, Mark :-)
4:55 PM
Bob S.
has left the room
Michael W.
Last question, I'm trying to make a preference settings
There is a AppCompatPreferenceActivity
Mark M.
that would be if you are using appcompat-v7 and AppCompatActivity
Michael W.
But read on many sources use the PreferenceScreen
Mark M.
a PreferenceActivity or PreferenceFragment uses a PreferenceScreen
I'm not aware of anyone using a PreferenceScreen directly, outside of a PreferenceActivity or PreferenceFragment
I'm not even sure that it is possible, though I've never really looked into it
5:00 PM
Michael W.
I also want to try that one.. Thanks
Mark M.
that's a wrap for today's chat
the transcript will be posted to https://commonsware.com/office-hours/ shortly
the next chat is Saturday at 9am US Eastern
have a pleasant day!
Michael W.
has left the room
Mark M.
turned off guest access

Tuesday, December 8

 

Office Hours

People in this transcript

  • Bob Snyder
  • Mark Murphy
  • Michael W