Office Hours — Today, April 29

Thursday, April 25

Apr 29
3:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
4:00 PM
EGHDK
has entered the room
Mark M.
hello EGHDK
EGHDK
Hey Mark, I haven't been on here in a while, but I have a boatload of questions in regards to heirarchy viewer.
Mark M.
how can I help you today?
go right ahead
EGHDK
Well, to start off, only emulators can run it, correct?
4:05 PM
Sherman
has entered the room
EGHDK
Not retail devices
Mark M.
by default, yes
(BTW, hi, Sherman -- be with you shortly!)
Sherman
Hi Mark... thanks
EGHDK
A rooted device can run heirarchy viewer correct?
Mark M.
EGHDK: however, if you add Romain Guy's ViewServer to your project, you can use Hierarchy View then
EGHDK
Exactly. But I want to know more about SECURE MODE
View paste
private static final String SYSTEM_SECURE = "ro.secure";
private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
Mark M.
that's a firmware issue, well outside my area of expertise
EGHDK
Okay, you can help sherman. I will come back with another question. hah
Mark M.
OK
Sherman: do you have a question?
Sherman
yep I do... let me know if you don't usually provide this kind of help... this is my first office hours
so, i am trying to build an app that involves mapping of information pulled from a web service that i have built
this data (XML/JSON) will be parsed and used my Google maps v2
by*
and then details will be modified
and then the data will be synced all at once back to the webserver and so on and so forth
i am wondering about a strategy to implement the syncing in android?
4:10 PM
Mark M.
um
that's rather broad
Sherman
hehe... okay
Mark M.
and 95% of it has nothing to do with Android, but rather with your Web service
Sherman
well, no...
imagine the file is already generated and it is on android
or on the device already
is there some kind of pattern that i can refer to for what i am trying to do?
Mark M.
since I am now rather lost, I cannot point you to a pattern
if I "imagine the file is already generated and it is on android", then there is no "syncing in android" that you need a strategy for
syncing, at least when used in mobile development, usually refers to synchronizing data between a mobile client and some server
Sherman
okay
Mark M.
so, are you trying to figure out how to update your file locally on the device?
Sherman
so syncing data between a mobile client and a server
Mark M.
or are you trying to figure out how to synchronize data from a device to a server?
Sherman
i guess i am trying to synchronize data from device to server
Mark M.
are you writing the Web service? or is it one somebody else wrote?
4:15 PM
Sherman
it would be a REST api that i wrote
4:15 PM
Sherman
for a server that i wrote
Mark M.
then what part(s) of "a strategy to implement the syncing in android" are you unsure of, so we can narrow down this discussion?
Sherman
so, i am going to pull a set of data from my server
it is probably going to be a XML/JSON
do i load that data into a SQLite database of some sort to manipulate the data?
Mark M.
that's one possibility
Sherman
then when i update the data, how should i be sending this information back?
Mark M.
using your REST API that you are writing
Sherman
right... so is that the best idea?
Mark M.
if by "that" you mean SQLite, I can't answer that, as I have no idea what your criteria are for "best"
if you are doing lots of piecemeal work with the data, or doing bulk updates of some specific facet (what would amount to a column), a database is awesome
if you are mostly just reading the data in and serializing it back out, and the "out" format would be what you are sending via REST to the server, you might just keep it in the files
4:20 PM
EGHDK
Okay Mark, so using a rooted device with hierarchy viewer is possible. I would also be able to see the id's of these views correct?
Mark M.
EGHDK: I presume a rooted device can work with Hierarchy View. I have never tried it, nor do I have any idea what limitations, if any, there may be.
but, if it works at all, presumably it gives you the same data as you would get with an emulator
Ron B.
has entered the room
Ron B.
Hi Mark
Mark M.
Sherman: in many respects, an Android device is not that different from a single-page Web application, particularly one using some sort of client-side storage
hence, if you have Web development experience, you might ponder how you would write the single-page application, then work on finding the proper Android analogues
Sherman
Mark: i was doing some reading and they mentioned building a content provider to do this sort of thing... do i need to do that?
Mark M.
you do not "need" to do that, though there may be use cases where you find it helpful (e.g., sharing data with other apps)
EGHDK/Sherman: let me take a question from Ron, and I'll be back with you shortly
Ron: do you have a question?
Ron B.
Yes, My app needs a tab bar on the bottom. I've been implementing with TabHost, but not TabActivity. I have a few questions. First, I know TabActivity is deprecated. Is TabHost within an Activity?
Mark M.
TabHost is a ViewGroup. It can be used from a regular activity, and I demonstrate that (IIRC) in my TabHost coverage in the book
4:25 PM
EGHDK
Question #2: (Not sure if I've asked you this or not) But what is the technical term for when you do (setContentView()) is that called inflating the layout? Also, when you say Button btn = (Button) findViewById(R.id.btn1) is that called "inflating the button"? I help people learn intro android, and I have to tell them to do that a lot, and I feel like there should be a term for it.
Mark M.
EGHDK: behind the scenes, setContentView() will use a LayoutInflater to inflate the layout. findViewById() finds views by their ID. I would not call that "inflating the button", as it has nothing necessarily to do with inflation.
Sherman: do you have another question?
Sherman
I do.
EGHDK
Question #3: Is there currently [or was there] a difference between opening up an application that had already been launched through the "recent apps" vs the apps launcher icon
Mark M.
Sherman: go ahead
EGHDK: I will be with you in a bit
Sherman
I am following along with your tutorials and I am trying to understand DatabaseHelper and ModelFragment (with analogues to web development)
EGHDK
No problem. I'm just listing them as I type! Take your time!
Sherman
would DatabaseHelper be the only class that would interface with my associated SQLite db?
4:30 PM
Mark M.
in the way I wrote that specific tutorial, yes
that's not the only implementation pattern that is available
you could use the aforementioned ContentProvider, and have it be the primary access point to the database
Sherman
in what situation would it be looking at another implementation pattern?
Mark M.
you could use an ORM framework, like ORMLite, in which case the models work with the ORMLite framework to interact with the database
etc.
you would be looking at another implementation pattern as part of your normal course of design and implementation
just because *one* set of tutorials shows *one* way of doing things does not mean that it is the *only* way of doing thngs
er, things
just as the existence of GWT doesn't mean that all client-side Web development is done in Java (translated by a GWT compiler into JavaScript)
Sherman
right... is there a place where i can find other ways of doing things? obviously i don't know how things are done in Android at this point.
Mark M.
I cover using a ContentProvider in a couple of chapters later in the book
I do not cover ORM frameworks at this time
my book is less on high-level design decisions and more laying out the tools in the toolbox that you have at your disposal
Sherman
is there a reason for that? Are ORMs resource intensive?
Mark M.
I do not cover ORM frameworks at this time because I can only type so fast :-)
historically, ORM frameworks' overhead was a fair bit, given the weak power of the devices
nowadays, the overhead is much more manageable
Sherman
okay... i am just trying to build my first app and i am having trouble linking things together so i am using your tutorial as a way of doing things that works
Mark M.
and there's nothing wrong with using the tutorials as an example
there is a wide gulf between "example" and "the one and only approach"
Sherman
of course.
Mark M.
occasionally, in Android, there is only one approach to a problem, and I try to call that out
otherwise, as the Perl people like to say, "there's more than one way to do it"
4:35 PM
Mark M.
so, in the case of the tutorial, I think (IIRC) that I isolated the database access in DatabaseHelper
and that's not an uncommon approach, for small apps with only a table or two
Sherman
you did yes.
Mark M.
Sherman: let me take questions from Ron and EGHDK, and I'll be back with you in a bit
Ron: do you have another question?
Sherman
yep
Ron B.
Following up on my question.. Yes, I was reading pages 2021-2024 of V4.7. So you're saying that this usage is supported and not deprecated? One thing I was looking for from TabActivity was the onTabSelected method or some way of knowing the user is in the current tab.
Mark M.
yes, TabHost and TabWidget are not deprecated
now, a bottom tab bar is an anti-pattern on Android
Ron B.
Anti-pattern?
Mark M.
tabs in Android go at the top
EGHDK
View paste
"I would not call that "inflating the button", as it has nothing necessarily to do with inflation." 
So what would you call that? There has to be some kind of term or phrase... no?
Mark M.
EGHDK: "finding the view by it's ID"
Ron B.
OK, political issue at work that I'll need to deal with. iOS apparently rejects tab buttons at the bottom and they want the apps to look similar.
I mean iOS rejects them at the top.
4:40 PM
Mark M.
whoever "they" is needs to get a clue
EGHDK
Create and initialize the view by finding it's id? Would that also be correct?
Sherman
heh
EGHDK
And yes Ron, don't use tabs on the bottom!
Mark M.
the only people who will see the iOS and Android app at the same time is the mysterious "they"
EGHDK
Exactly
Mark M.
they should be aiming for something that is natural for each platform, not trying to enforce some ill-conceived "look similar" rule
EGHDK: findViewById() does not create anything
Ron B.
Regardless of that how do I know the user has selected the tab for my activity?
Mark M.
what do you mean by "the tab for my activity"?
EGHDK
The same reason iOS rejects tabs on top, Android "rejects" them on bottom.
Mark M.
there is only one activity in this discussion AFAIK
Ron B.
I use setContent and an Intent to go off to another Activity, but not a TabActivity.
EGHDK
What would you tell a beginner android student when they have to type out: Button btn = (Button) findViewById(R.id.btn1); Sorry If I'm being picky, but I'd like to pick your brain.
Mark M.
Ron: *that* is deprecated
Ron: you asked, originally, if you could use TabHost and TabWidget in a regular activity, and that is possible and is still supported
activities-in-tabs is what was deprecated (ActivityGroup and its TabActivity subclass)
4:45 PM
Mark M.
EGHDK: it's the same as finding a DOM node by its ID (e.g., using a CSS selector), or finding a file by a filename, or finding a building by its street address, or finding a book by its ISBN, or...
Ron B.
In this app, each tab would represent an entirely different interactive user interface...
EGHDK
Okay, I just want to make sure I'm explaining it right. I've been doing this for a while... but I'm still no expert. heh.
Mark M.
Ron: you would implement that using views or, more likely, fragments
e.g., use FragmentTabHost instead of TabHost
EGHDK
Question #3: Is there currently [or was there] a difference between opening up an application that had already been launched through the "recent apps" vs the apps launcher icon
Mark M.
Sherman: if you have other questions, chime in -- we're kinda in a free-for-all mode now
Sherman
no problem... just taking it all in
Mark M.
EGHDK: by default, there should be no difference. If you tinker with launchMode in the manifest, there might be a difference, but I haven't experimented much in that area
EGHDK
Perfect.
Sherman
i'm still trying to understand ModelFragment and it's role in EmPubLite app... how do I know if I need a class like that in my app?
Mark M.
Sherman: ModelFragment is designed to help retain data across configuration changes (e.g., screen rotations)
EGHDK
I wonder if you can answer this fairly quickly. You said "occasionally, in Android, there is only one approach to a problem, and I try to call that out" Can you think of any off the top of your head? I find that statement really interest. Maybe blog post idea?
Mark M.
Sherman: I cover configuration changes and various ways of dealing with them in the book -- using setRetainInstance(true) on a fragment (like a dedicated ModelFragment) is one approach
4:50 PM
Mark M.
Sherman: here's a recent blog post on the topic: http://www.androiddesignpatterns.com/2013/04/re...
EGHDK: "Can you think of any off the top of your head?" -- AlarmManager for wake-up-the-device-based-on-time events
EGHDK: "Maybe blog post idea?" -- I'm not sure how
Ron: if you have additional questions, or ones I missed, chime in
EGHDK
Cool. Alright, last two questions. 1. Will you be attending Google I/O 2. Do you still have the links to the presentation you gave at BABBQ?
Mark M.
1. No
Sherman
so say i have a map
Mark M.
"i have a map"
Sherman
and i have like 200 markers i want to put onto that map
Mark M.
oh, no, wait, you didn't mean that literally...
:-)
Sherman
hah
would i should probably try to retain that information between screen rotations?
EGHDK
Awesome thanks mark. That hotdog reference you made still makes me laugh till today (and it still makes sense) I'm signing off. Thanks for your time.
4:55 PM
Mark M.
EGHDK: you're very welcome
Sherman: is the data for the 200 markers *only* going to be used by this *one* activity?
Sherman
yes
well...
data for all 200.. yes... but eventually i will need information from 1 single marker
in another activity
Mark M.
OK
you have two issues to consider: how will this one activity get to the 200 markers' worth of data, and how will other activities get to data as needed
as usual, there are several approaches
Sherman
this one activity will pull this information from
DataHelper?
Mark M.
you could say that each activity will go to the database to get the data as needed
in that case, the activity with the map and 200 markers would probably use a retained fragment to hold onto the marker data
whether that is a dedicated ModelFragment-style approach, or just part of another fragment that needed to be retained for other reasons, is up to you
then your other activities would need to work with the same singleton DatabaseHelper
the other major approach says that you cache the 200 markers' worth of data in memory
this saves repeated database I/O, at the cost of managing the memory
you'd probably use some sort of singleton MarkerManager (or whatever) that loads the data as needed and hands it out to requesters
5:00 PM
Mark M.
in that case, you don't need to retain anything in the map activity, as it can just grab the cached copy after the configuration change
Sherman
is database I/O considered an "expensive" operation in Android?
Mark M.
well, it's disk I/O, and disk I/O can be slow
particularly for lots of data, or complex operations, or on devices with low-end on-board flash
Sherman
and if i was to cache the 200 markers in memory what would I be looking at to do that?
Mark M.
again, you'd have some sort of singleton responsible for managing the cache, which the activities would then use as needed
Sherman
okay... my advantage is that I know only Nexus 7s are going to be accessing this
EGHDK
What is it called when you have to change the type of something in java?
Like (Int) when using Math?
Mark M.
EGHDK: if you mean (float)value, that's "casting"
Sherman
so something like a CacheHelper?
Mark M.
Sherman: you can call it whatever you want
EGHDK
Mark: Yes! I meant casting. Haha I couldn't remember the term. Thanks
Mark M.
and that's a wrap for today's chat
Sherman
thanks Mark.
Mark M.
this transcript will be archived at http://commonsware.com/office-hours/ shortly
next chat is Thursday at 10am Eastern
have a pleasant day, all!
Sherman
u too!
EGHDK
has left the room
Sherman
has left the room
Ron B.
has left the room
Mark M.
turned off guest access

Thursday, April 25

 

Office Hours

People in this transcript

  • EGHDK
  • Mark Murphy
  • Ron Bruckman
  • Sherman