Office Hours — Today, May 1

Thursday, April 26

May 1
9:50 AM
Mark M.
has entered the room
9:55 AM
Mark M.
turned on guest access
10:00 AM
Jumana A.
has entered the room
Jumana A.
hi mark!
Mark M.
howdy, Jumana!
how can I help you today?
Jumana A.
going ok
ive been waiting for this session!
i have a few questions to shoot! :-)
Mark M.
go ahead
Bruce F.
has entered the room
Jumana A.
Mark, my app is something like " a quote a day" where random quotes are displayed - one new one everyday (well thats what atleast i want to be able to do!i have a long way to go). Now when these quotes are displayed, I also want to give the user the option of sending it by email. For that Im providing them an image button to click on. On click of which, the user will be shown all email clients that have been installed on his device. How do i do that, mark? I gathered from all your posts in stackoverflow, that you are not a big fan of restricting users to share via sms or email only. And i totally agree with you. But i really need to provide him only the email options :-)
Justin M.
has entered the room
Mark M.
use ACTION_SENDTO and a mailto: Uri of the specific person to email it to
Jumana A.
The clients will not be shown in that case?
Mark M.
what "clients"?
Jumana A.
email clients like gmail/ yahoo mail
Mark M.
(BTW, howdy, Bruce & Justin! be with you shortly)
first you say you only want email options, now you say you want to block email options
which is it?
Jumana A.
im sorry if im not clear - i want the user to be shown the gmail, yahoo options on click of that button
Mark M.
then use ACTION_SENDTO and a mailto: Uri of the specific person to email it to
10:05 AM
Jumana A.
ok will try that
Mark M.
let me take questions from others, and I will come back to you in a bit
Jumana A.
sure
Mark M.
Bruce: do you have a question?
Bruce F.
Yes, and hello Mark.
My question is about reusing ActionBarSherlock, or any other library, between workspaces. I'm just recompiling every time I start a new workspace. Is there a better way?
Mark M.
beats me
I only use one workspace
I use working sets, not workspaces, to organize my projects
you might try asking that on the ABS Google Group
somebody there probably uses multiple workspaces
sorry I could not help on that one
Bruce F.
I'll probably just use working sets instead.
as soon as I figure out how to do that
Mark M.
AFAIK, you'd use multiple workspaces if you have lots of different plugins, or need different Eclipse settings
working sets are just ways of only showing a subset of projects in the Package Explorer
Justin: do you have a question?
Justin M.
I do, it's a little more general....
Kind of an architecture question. I'm working on a project where I've been separating out major areas of responsibility of the app into separate services...
10:10 AM
Justin M.
I know I've read that there shouldn't usually be a need for more than one service in an application...
One of the services is derived from Service and the other from IntentService that I have right now, and both make sense to use those respective superclasses based on what they're doing...
But I'm wondering if I'm going to run into any problems if I had any more services than these two in the app?
This is really not a specific question
Mark M.
I would not say you will encounter "problems"
Justin M.
Just looking for some general guidance. I can supply more info to clarify if that helps
Mark M.
however, it is dubious whether you will get any value out of having more services than that
having the two you describe, with different base classes, makes sense
bear in mind that business logic does not have to be implemented on a subclass of Service
too many developers think that Activity, Service, et. al. are means of code organization
Justin M.
One controls a socket where I'm listening for connections and receiving requests (the Service-derived class)...
Mark M.
they're not
Justin M.
And the other then processes the requests in a FIFO fashion (the IntentService-derived class)
Mark M.
right, and those function sufficiently differently (e.g., lifetime) that you need them separated as they are
or, more accurately, while you could drop the IntentService and roll your own FIFO queue in your other service, that doesn't buy you anything.
Justin M.
OK, that's good then... If I want to then send HTTP requests to a server and then receive responses, that's where I was thinking of a third service....
Mark M.
why would that not be another capability of your existing IntentService?
Justin M.
OK, actually that's what I was going to ask
Because that's really what an IntentService would be good for then...
Mark M.
something in the commands (Intents to onHandleIntent()) distinguish the cases
10:15 AM
Mark M.
if it's too much code, then refactor the business logic into some sort of command-handler classes
the only downside of an IntentService being overloaded this way is that you only have one background thread
so multiple commands cannot be processed in parallel
one of these days, I'll get around to writing an AsyncService that uses the thread-pool flavor of AsyncTask to give you IntentService semantics with multiple threads
Justin M.
So I shouldn't be concerned that the service is going to be doing unrelated types of functionality then? Just use the appropriate service based on whether I want to process requests in a queue or as something long-running with state?
Mark M.
pretty much
again, Service is not a unit of code organization
*classes* are the unit of code organization
if a Service gets too complex, refactor business logic into other classes, not other services
let me take questions from the others, and I'll swing back to you in a bit
Justin M.
OK, fair enough. I have to think it through, but I think it would be OK for processing received data and then outgoing HTTP request/responses to be queued together (i.e. not running in parallel)
OK, I'm done actually, thanks a bunch!
Mark M.
Jumana: do you have another question?
Jumana A.
when the user is shown the quote for the day, I want the user to be able to pinch the screen so that the font size becomes smaller or bigger. is that possible to be implemented?
Mark M.
you could use a GestureDetector to detect the pinch, then call setTextSize() as needed, I suppose
or, if you are rendering the quote in a WebView, use its standard zoom capability
Jumana A.
no its not webview
its in a scroll view, textview
10:20 AM
Mark M.
the ScrollView could cause problems with GestureDetector
and I don't know if GestureDetector handles multitouch
Jumana A.
oh is it?
ok
Mark M.
you might need to create a PinchableTextView subclass of TextView and handle the touch events yourself
there are a few ImageView implementations that offer pinch-to-zoom, which you could use as a basis
Jumana A.
can i refer to them from somwhere?
do you know any references?
Mark M.
not handy, sorry
should be findable via a search engine
Jumana A.
np
ok
Mark M.
Bruce: do you have another question?
Bruce F.
Yes, this may be more of a Google API question though.
View paste
My app will have users make (infrequent) image downloads, presumably from Google. The API appears to want to charge per download. Is that your understanding?
Mark M.
what API are you referring to?
Bruce F.
The google image api was deprecated, I forget the name of the one as a replacement
Should have come here armed with the reference
Mark M.
most likely, I haven't used it
I don't use much in the way of Google APIs
so I haven't a clue on pricing
I'm not doing very well with your questions today... :-(
Justin: are you still question-less?
10:25 AM
Bruce F.
So I could simply steer the user to google images, with using he api?
Mark M.
Bruce: I have no idea
Jumana: do you have another question?
Jumana A.
yes...My app reads the quotes from an xml that I have created. I want the user to be able to mark any of the displayed quotes as his favorite so he can refer to them again. How do i best implement that? Do i have to create something similar to a database? (Please note Im a complete novice)
Mark M.
a database would be a likely option
you could edit the XML and add a "favorite" flag there, but that becomes a problem if you want to replace the XML later on with new/different quotes
you could store the bookmark data in some other non-database file (XML, JSON, etc.)
any persistent data store you like would work, though SharedPreferences' API is not well-suited for your case
Jumana A.
which is better - storing in database or some non db file?
Mark M.
that depends entirely on your personal criteria for "better"
I cannot answer that in the abstract
Jumana A.
faster i mean
Mark M.
faster to run? faster to code? faster in some other way?
Jumana A.
faster to run
Mark M.
that too cannot be answered in the abstract
it depends upon what you cache in memory, how you plan on accessing the data, etc.
10:30 AM
Mark M.
this has little to do with Android and everything to do with standard persistent data programming design
Jumana A.
mark - this is silly - but i have to ask...by "database" you mean...??
with reference to your books?
Mark M.
Android integrates SQLite, as is covered in _The Busy Coder's Guide to Android Development_
Jumana A.
ok
not content providers right?
Mark M.
ContentProvider is a facade over your choice of persistent data store, typically SQLite
ContentProvider itself does not store anything
Jumana A.
ah ...ok
Mark M.
let me check with the others and I'll get back to you shortly
Bruce: do you have another question, perhaps one I can answer? :-)
Jumana A.
ya ok sure
Bruce F.
I'll try, but it's related to my previous question.
Default behavior on android is that a long press on an image in a webview downloads the image. I want to make use of that image. Any ideas?
Justin M.
I'm back now, when it's my turn again, I have a quick question, no rush
Mark M.
hmmm... never tried that
do you have any sense if WebView itself is downloading it?
or is it launching a browser app, which is downloading it?
Bruce F.
no, I don't know
Mark M.
if WebView itself is downloading it, a WebViewClient might be informed of the event
either onLoadResource() or shouldOverrideUrlLoading(), perhaps
Bruce F.
thank you
10:35 AM
Mark M.
oh, there's also shouldInterceptRequest(), though that's new for API Level 11
I'd see if any of those get control
Justin: OK, fire away with your questino
er, question
OK, I'll try again later
Jumana: do you have another question?
Jumana A.
yes...
the quote of the day should be coming as notification say once every day( or depending on the frequency the user sets) instead of the user having to open the app everyday. How do i implement that?
Mark M.
use AlarmManager to schedule the daily event
Jumana A.
ok
Mark M.
that is covered in _The Busy Coder's Guide to Advanced Android Development_, though more with an eye towards the "check for new email every 15 minutes" scenario
10:40 AM
Jumana A.
oh ok
will refer to that
Mark M.
Bruce: do you have another question?
Bruce F.
not at the moment, thanks
Mark M.
Justin: do you have another question?
OK, if anyone has a question, chime in
Jumana A.
Like i said, Im reading the quotes and related details like author etc from an xml. And im using XML pull parser to retrieve quotes. Is that the most efficient way of doing it?
Mark M.
XmlPullParser, speed-wise, is roughly the same as SAX
if you prefer the XmlPullParser API, feel free to use it
Jumana A.
when i run the app, it takes a few seconds for the quote to be displayed, thats why the doubt
Mark M.
how big is the XML file?
Jumana A.
not much at all
30 kb
Mark M.
that seems slower than I would expect
10:45 AM
Mark M.
you might consider using Traceview to determine exactly where your time is being taken up
Traceview is covered in _Tuning Android Applications_
Jumana A.
oh ok
oh great
will refer to that
is sqllite commonly used in apps for data storage?
Mark M.
it's probably the most popular persistence mechanism
Jumana A.
im considering moving all quotes and all its details into sqllite
Mark M.
that's a possibility
Jumana A.
instead of xml
Mark M.
how are your quotes getting to the device?
Jumana A.
as of now , xml
Mark M.
no, that is how you are storing them
how are they getting to the device?
Jumana A.
(scratching my head) not sure what youre asking
Mark M.
are you downloading them off the Internet? is the XML packaged in res/xml/ of the app? something else?
Jumana A.
oh no it will be packaged with the app
under res/xml
Mark M.
and you are using getResources().getXml() to load it?
Jumana A.
yes
10:50 AM
Mark M.
hmmm... then I do not think the problem is in the XML parsing
XML resources parse about ten times faster than plain XML files
there is no way a 30KB XML resource is taking seconds to parse
hence, I again recommend Traceview -- find out where your problem really is, before optimizing things that may not need optimizing
Jumana A.
oh ok ...ill have a look at the trace then
if bruce and justin dont have any more questions, i would like to ask more pls
Bruce F.
none from me.
Mark M.
Bruce? Justin? any questions?
Justin M.
Yes, I do, sorry I've been at the office, distracted
Just one
Might be in your books already and I missed it..
What is the best way to use SQLiteDatabaseHelper with a database with multiple tables? A lot of the examples I've seen in the past only show how to get it to work with one table. Wondering if you have examples of best practices or where I could look for more info
Mark M.
SQLiteOpenHelper is not dramatically different for more tables
you would need to add more statements to onCreate() and onUpgrade()
to set up/upgrade the other tables
that's pretty much it
am I missing something?
10:55 AM
Justin M.
No, it's probably me. I really don't have a well-formed question about it... so I'll come back with something more specific in future sessions. Thanks :-)
Mark M.
OK
Jumana: do you have another quick question?
Jumana A.
yes ...mark, if im having a single table to store quote nos, quote texts and whether favorite or not. ANd in future if i need to add more quotes into the app, how is the data in the "favorite or not" column maintained?
in other words, how is the user-related data maintained?
Mark M.
if you are using SQLiteOpenHelper, you will be given control if, when the user upgrades their app, Android detects that your database table structure needs updating as well
you would then execute the appropriate SQL statements (e.g., ALTER TABLE) to add any columns
or INSERT statements to add more quotes
or whatever
Jumana A.
ohok great
thanks mark...will shoot more on thursday! :-)
Mark M.
OK
11:00 AM
Mark M.
and that's a wrap for today's chat
next one is Thursday at 4pm Eastern
Bruce F.
thanks
Bruce F.
has left the room
Mark M.
have a pleasant day, all!
Justin M.
Thanks, take care
Jumana A.
has left the room
Justin M.
has left the room
Mark M.
turned off guest access

Thursday, April 26

 

Office Hours

People in this transcript

  • Bruce Forkush
  • Jumana AM
  • Justin Munger
  • Mark Murphy