Office Hours — Today, October 22

Thursday, October 20

Mark M.
has entered the room
Mark M.
turned on guest access
Chandra S.
has entered the room
Chandra S.
Hi Mark
Mark M.
hello, Chandra!
how can I help you today?
Chandra S.
How to implement a download function of a big files (such as 50 MB). Is the Loader function enough?
Mark M.
IMHO, no
Chandra S.
If the download stopped before it finished, can we resume again?
Mark M.
that would depend on your HTTP API and whether it supports some sort of resume functionality
for larger files like that, I would recommend using an IntentService, so your process is unlikely to be terminated while the download is in progress
Chandra S.
That's also my confusion.. About Loader and IntentService difference
Oct 22
9:00 AM
Chandra S.
Who is getting more time in the lifecycle?
9:00 AM
Mark M.
I do not know what "getting more time in the lifecycle" means, sorry
Chandra S.
If it required let say 1 hour to download the file, will the Loader or IntentService will stay if user close the foreground?
Mark M.
the Loader will not
mostly because the activity will be destroyed *long* before the hour is up
"if user close the foreground" might directly destroy the activity (BACK) or simply cause the process to be terminated eventually (HOME, RECENTS, etc.)
a Loader is mostly for configuration changes, nothing more
Chandra S.
So if user close the foreground, the loader also will be terminated?
Mark M.
it can be, if the user presses BACK
Chandra S.
Yes I mean that user press back
Mark M.
a Loader should not be doing anything more once its hosting activity is destroyed; otherwise, that is a buggy Loader
Chandra S.
I see.. I thought that it will be remained also
So in your appinars, are you using the IntentService?
9:05 AM
Mark M.
if you mean is Community Theater downloading appinars via an IntentService, then yes
Chandra S.
I see.. ok2 thanks
I have another question regarding the app also
How did you implement search function in the the busy coder app in the Android? Since it's quite fast
Mark M.
I use SQLite and FTS3
there's a chapter on that in the book
when I release an update, I have a Ruby script that generates an FTS3 table in a SQLite database, based on the book contents
that gets packaged as an asset in the APK
I use SQLiteAssetHelper to unpack it at runtime (also covered in the book)
then, your search queries just go against the FTS3 table
Chandra S.
I see.. Thanks, I will read on that one
I have another question also regarding the storage, what's the difference between internal and phone storage?
Mark M.
I do not know what you consider "phone storage" to be
9:10 AM
Mark M.
Android has removable storage, at least officially on Android 4.4+: https://commonsware.com/blog/2014/04/09/storage...
I do not know whether you consider "phone storage" to be external storage, removable storage, or something else
Chandra S.
Hmm I just saw it on my phone actually :-D I'll upload it on a moment
Can we write on all of them?
Internal, external, and removable
Mark M.
your app can write in your app's designated portion of internal storage
your app can write to external storage, if it holds proper permissions
ndrocchietto_ivano
has entered the room
Mark M.
you do not have arbitrary access to removable storage on Android 4.4+
this is all covered in the chapter on file I/O in the book
let me take a question from Ivano, and I will be back with you shortly
9:15 AM
Mark M.
Ivano: your turn! do you have a question?
Chandra S.
Ok
ndrocchietto_ivano
ciao Mark, I have a question regarding Mockito setting. I set Mockito as you indicated
but the method of mockito under junit test are not recognized( are red) and i found on SO that the solution is
one sec i am finding it
View paste
is this the solution but i do not get it  2
down vote
accepted
	

If you want pure unit tests, instead of instrumentation Android tests, you have to create your test classes under src/test/java directory and change test artifact to 'Unit Tests' in Android Studio (in Build Variants tool window).
Mark M.
um, well, that's what I describe in the book
the section on Mockito is in the chapter on unit tests
ndrocchietto_ivano
mmh
Mark M.
unit tests run on the JVM of your development machine
ndrocchietto_ivano
yes
Mark M.
whereas instrumentation tests run on Android (device/emulator)
ndrocchietto_ivano
yes
Mark M.
so, the Mockito example uses testCompile to pull in Mockito, not androidTestCompile
and the Mockito example has the Mockito-using test cases in test/, not androidTest/
ndrocchietto_ivano
i know that, i used
Mark M.
and to run them, you need to run the unit tests
9:20 AM
ndrocchietto_ivano
View paste

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.android.support:appcompat-v7:24.2.1'
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-all:1.10.19'

//    testCompile 'junit:junit:4.12'
//    testCompile 'org.mockito:mockito-core:1.10.19'
//    androidTestCompile 'com.android.support.test:rules:0.4.1'




}
what i do not understand is what means "change test artifact to "unit Tests" in Android Studio(in Build Variant tool window)
is something with flavors?
Mark M.
ah, that part has changed, due to changes in Android Studio
there used to be a drop-down in the Build Variants tool in Android Studio to let you choose whether you were working with the instrumentation tests or unit tests
ndrocchietto_ivano
I see
Mark M.
that is no longer needed
ndrocchietto_ivano
OK thanks
Mark M.
let me take a question from Chandra, and I will be back with you in a bit
Chandra: back to you! do you have another question?
ndrocchietto_ivano
OK
Chandra S.
View paste

http://tinypic.com/view.php?pic=16gesnd&s=9
http://tinypic.com/view.php?pic=142ske8&s=9
http://tinypic.com/view.php?pic=oadee1&s=9
That is in my phone, internal, SD card, and phone storage
Mark M.
you would have to ask your device manufacturer what that means
that is not part of standard Android
Chandra S.
I see
9:25 AM
Chandra S.
I also curious on why Whatsapp can not save images/videos on the SD card
Mark M.
you would have to ask them
ndrocchietto_ivano
View paste
(ah ah:) )
Mark M.
they could use the Storage Access Framework on Android 4.4+ for that (ACTION_CREATE_DOCUMENT)
Chandra S.
Since I have a plan to build the app that write to storage, so just curious whether there's a restriction
Mark M.
or they could use getExternalFilesDirs()/getExternalCacheDirs() on Android 4.4+
Chandra S.
I see.. Ok thanks I'll check on that
Mark M.
all of that is also covered in the book
let me take another question from Ivano, and I will be back with you afterwards
Chandra S.
Ok
Mark M.
Ivano: back to you! do you have another question?
ndrocchietto_ivano
well yes is simple but you do not manage dagger 2
Mark M.
I have never used Dagger 2, sorry
ndrocchietto_ivano
OK
i have JB
haI hate JB
I hate JB, made my life difficult:(
9:30 AM
Mark M.
it's a little older
the three Jelly Bean versions (4.1/4.2/4.3) are starting to fade out -- ~15% of the Google Play ecosystem at the moment
(plus another ~3% of versions older than that)
ndrocchietto_ivano
sorry
I mean the coder that invented retrofit 1/2 and dagger 1 2 from square
Mark M.
sorry, I don't know who that is
ndrocchietto_ivano
jack wharton
Mark M.
I think you mean Jake Wharton
ndrocchietto_ivano
yep
Mark M.
Dagger 2 is maintained by Google now IIRC, so I do not know how much Jake is involved
ndrocchietto_ivano
ah
Mark M.
anyway, let me take another question from Chandra, and I'll turn back to you in a while
Chandra: back to you! do you have another question?
ndrocchietto_ivano
OK thanks
9:35 AM
Chandra S.
Actually this is a basic question :-D What's the difference of AppCompat, Actionbar, and Toolbar?
Mark M.
well, the action bar is the stripe across the top of your activity that has your activity's title
that was added to Android with API Level 11 (Android 3.0)
in Android 5.0, the refactored the code, creating Toolbar, which gives you an action bar-style widget that you can place wherever you want
the appcompat-v7 library offers a backport of the action bar and Toolbar that works back to API Level 7
if your minSdkVersion is lower than 11, and you want to use an action bar, you should use appcompat-v7
if your minSdkVersion is lower than 21, and you want to use a Toolbar, you should use appcompat-v7
Google's attitude is that you should *always* use appcompat-v7, but I feel that it should be an explicit decision
Chandra S.
I see.. Got it, Mark.. Thanks
Mark M.
the book has chapters on the action bar, on Toolbar, and on AppComapt
er, AppCompat
Chandra S.
What is library that is in the appcompat v21?
Mark M.
there is no appcompat-v21 library that I know of
9:40 AM
Mark M.
I do not see one in my copy of the Android SDK
so, I am not sure what you are referring to
at this point, if either of you have a question, go right ahead and ask
ndrocchietto_ivano
Not really. Kotlin,Testing,Jenkins and ..JW, are taking all the time supposed to be pure Android time:(
but thanks Mark will come back soonish
Mark M.
OK
9:50 AM
Mark M.
if either of you have a question, just ask
ndrocchietto_ivano
tabula rasa
9:55 AM
ndrocchietto_ivano
just a curiosity
the xml files where usually is the layout at compile time become kind of java instructions?
Mark M.
not really
all the XML resources (and the manifest) get "compiled" into a "binary XML" format
ndrocchietto_ivano
gorsh!
that is why you do not need to test!
Mark M.
that format is optimized for speed in reading
ndrocchietto_ivano
I thought there was a kind xml parser under the hood
fascinating!
Mark M.
at runtime, a custom implementation of the XmlPullParser can read in the "binary XML", about 10x faster than the original ordinary XML
ndrocchietto_ivano
i trust you
but so what happens when I give info programatically in Java, for instance if I take an element of the background in the code, let's say an attribute as I want to use an if condition
will still get compiled in binary XML format?
Mark M.
no
ndrocchietto_ivano
double gorsh!
Mark M.
the act of inflating a layout creates a tree of Java objects representing the UI (e.g., LinearLayout, TextView)
10:00 AM
Mark M.
all your runtime manipulations go against those objects
resources are read-only at runtime
ndrocchietto_ivano
I see
with a hierarchy on onMeasure
Mark M.
yes, and all the rest of the ViewGroup work
and that's a wrap for today's chat
ndrocchietto_ivano
that is why when i debug onMeasure with a break point I have a lot of stop on the same row!
Mark M.
the transcript will be posted to https://commonsware.com/office-hours/ shortly
ndrocchietto_ivano
thanks
Mark M.
the next chat is Tuesday at 4pm US Eastern
ndrocchietto_ivano
OK
Mark M.
have a pleasant day!
ndrocchietto_ivano
cheers
Chandra S.
has left the room
ndrocchietto_ivano
has left the room
Mark M.
turned off guest access

Thursday, October 20

 

Office Hours

People in this transcript

  • Chandra Siahaan
  • Mark Murphy
  • ndrocchietto_ivano