Office Hours — Today, May 7

Thursday, April 29

May 7
9:25 AM
Mark M.
has entered the room
Mark M.
turned on guest access
Justin M.
has entered the room
Mark M.
howdy, Justin!
Justin M.
Hi there Mark, good morning :-)
Just two questions for you today whenever you're ready
9:30 AM
Mark M.
fire away
Justin M.
Cool, these are more general best practice type questions...
First, I was wondering with an applications Resources, I know I can get access to them through an Activity, but there are times where I need to access them from another class. My particular example is an Overlay subclass for mapping...
It seems kind of bulky to constantly pass a reference to a Resources object around and around to different classes that need it, is there a better way to approach this, like having a singleton object you can access a Resource object through globally?
Mark M.
all of that is fairly dangerous
I'm not sure you get the same Resources object back after a screen rotation, for example
Justin M.
Ahhhh, OK, that's a good point
Mark M.
that's why I usually keep my Overlay classes as inner classes of the MapActivity
Justin M.
Ahhhhh
Gotcha
Mark M.
easy to access the resources without worrying about having the wrong ones
Justin M.
OK, cool deal
Here's the second question...
9:35 AM
Justin M.
In an app that my team is working on, there's discussion about building an ActivityManager to manage launching all the different intents, something like a traffic cop for the app. It would be analagous to a UINavigationController in the iPhone world if you're familiar with that at all...
9:35 AM
Mark M.
Eye-fone?
:-)
Justin M.
I'm wondering if that's really necessary to do since the OS handles the stack of intents/activities for you already?
LOL, yeah ;-)
NetApex
has entered the room
Mark M.
I would not create a traffic cop app, personally
er, not app -- class
NetApex
Good morning
Mark M.
having a bunch of static Intents somewhere is not a bad idea
Justin M.
Seems like we might be building an extra layer of complexity that could actually be detrimental, especially when we leave the app to access the phone, camera, etc
Mark M.
I would tend to agree
Brian C.
has entered the room
Mark M.
BTW, howdy, NetApex!
and, howdy, Brian C!
Brian C.
Hi, Mark
Mark M.
Justin: about the only time I've centralized that sort of thing is exception handling, for logging via Flurry or whatever
Justin M.
OK, cool, that makes sense, just wanted a sanity check on that, I'll have to see what the architect person has come up with and then maybe I'll understand better what he's come up with. I'm good for now, thanks a bunch, have a great weekend!
Brian C.
I have a question.
Mike R.
has entered the room
Mark M.
Howdy, Mike R!
Mike R.
Hi everyone.
Mark M.
Brian: ok, go ahead
Brian C.
I am converting an iPhone navigation based app to Android.
In the navigation based app, you push view controllers onto a stack
9:40 AM
Brian C.
I am mapping that to Android Activities called via Intents
that seems like the right paradigm, but I also saw somue statistics that said that calling activities is heavyweight
Mark M.
not particularly, IMHO
Brian C.
ok cool
i like it that way because of the back button
Mark M.
moreover, it's the expected model for most things
right
it helps if you think of building your Android app as if it were a Web app
activity = link to the next page of the Web app
BACK and HOME then behave like, well, BACK and HOME of a Web browser
Brian C.
I think it will be a little confusing for my client, because he'll be wondering where the back button that appears in an iPhone nav bar
but I think it's better to use android like android
Mark M.
agreed
Brian C.
and not try to replicate iphone behavior verbatim
Mark M.
hopefully, your client will be interested in what the app's *users* will expect
Brian C.
i like that web page analogy
ah, good point
ok, i'm good. thanks, mark
Mark M.
NetApex: did you have a question?
or, does anyone have a question?
Mike R.
Mark, I've got a few
9:45 AM
Mark M.
go ahead
NetApex
I am good for right now
Mike R.
ok Activity Lifecycle.
Mark M.
a great way to get exercise
I am riding one right now
...oh, wait...
you meant in Android
Mike R.
I'm trying to relate user/phone actions to what gets called in the activity
Mark M.
:-)
NetApex
lol
Mike R.
When the user presses the Back button, what gets called? How does that differ from when the user presses the Home button?
I'll just ignore your attempts at humor for the moment.
Mark M.
wow, tough crowd
anyway
when BACK is pushed, onPause() and onStop() are called, in that order
and onSaveInstanceState() is called in there as well
when HOME is pushed, the same thing happens
whoops
BACK also gets onDestroy() called, after onStop()
onSaveInstanceState() should be called around when onPause() is called, but it's not exactly deterministic
so:
BACK = onPause() -> onStop() -> onDestroy(), plus onSaveInstanceState()
HOME = onPause() -> onStop(), plus onSaveInstanceState()
that's what happens right away, in any case, by default, for those buttons
9:50 AM
Mike R.
ok an activity is invoked by StartWithResult. it appears that the calling activity gets a call to onActivityResult before the called Activity gets a call to OnStop. Is that accurate?
Mark M.
I don't think that's necessarily guaranteed
but that may be the current implementation
Mike R.
ok. i need to update some system state when the user presses the back button, and the calling activity needs access to that information.
Mark M.
usually, that's via startActivityForResult() and onActivityResult()
Mike R.
I've been doing the updates in OnStop, but the calling activity is reading the system state in onActivityResult before the called activity gets OnStop.
Mark M.
ah, you're too late
use onPause() for setResult()
Mike R.
ok I'll try that
Now. ListViews
trying to understand on to refresh a listview when the data changes
9:55 AM
Mike R.
using an array adapter
Mark M.
for ArrayAdapter, modify its contents via add(), insert(), and remove() on the ArrayAdapter itself
Mike R.
a called activity will add or delete members from the backing data array
Mark M.
the ListView will automatically update
ick
aishwarya
has entered the room
Mark M.
in that case, you'll need to try messing around with notifyDataSetChanged() or something on the adapter
Mike R.
so far the only way i've been able to make it work is by re-creating the backing array, and recreating the array adapter.
but it's kind of pokey.
Mark M.
That shouldn't be needed
However, ArrayAdapter is not really designed for some sort of shared array as the backing store
More designed for use within a single activity
Will you be moving the array contents into a database sometime?
Mike R.
no. they're actually in a hash map
aishwarya
Hello
Mark M.
howdy, aishwarya!
Mike R.
that gets serialized to disk
Mark M.
Mike R: then you should consider writing your own adapter
that'll be more efficient than trying to sync a HashMap and an ArrayAdapter
subclass BaseAdapter
Mike R.
maybe in release 2
aishwarya
i am facing some problem with the wake locks in my application. I have tried using it the way given in your tutorial (plus with a few changes)
Mark M.
call notifyDataSetChanged() when you make the data change
aishwayra: I will get to your question once we are finished with Mike R's question, thanks
Mike R.
final question: is there a spinning ball progress widget in Android to show activity?
10:00 AM
Mark M.
ProgressBar
aishwarya
i have used acquiring the wakelock in WakefulIntentService itself , then created an activity from there, and then released the lock
Mark M.
though it's more of a circle than a ball
aishwarya: I will get to your question once we are finished with Mike R's question, thanks!
Mike R.
good enough. thanks
aishwarya
ok
Mark M.
OK, now to aishwayra
aishwarya
no probs
Mark M.
why are you starting an activity from a WakefulIntentService?
and what sort of problem are you running into with your current implementation?
aishwarya
beacuse i need to do that, thats my app's requirement
that i need to start an activity immediately after waking up the device
.
Mark M.
that is very unwise
to the point of being unacceptable
aishwarya
the problem is that it does wake the device often , but not always
why so?
my app is like an alarm clock
Mark M.
oh wait, sorry
my mistake
I was thinking you meant you wanted to pop up an activity immediately after a reboot
aishwarya
noo
Mark M.
(wow, three days in Europe and my brain turns to mush...)
you are going to need to grab the WakeLock in the BroadcastReceiver
like the WakefulIntentService samples show
Otherwise, the phone may fall asleep after onReceive() returns and before you get a chance to grab a WakeLock in your service
10:05 AM
aishwarya
but why wont it work if i grab it in wakeful intentservice
Mark M.
As I said: the phone may fall asleep after onReceive() returns and before you get a chance to grab a WakeLock in your service
also, since the WakefulIntentService WakeLock is released after doWakefulWork()...
Calvin S.
has entered the room
Mark M.
...the phone might fall asleep before the activity launches
For your case, I would recommend not using WakefulIntentService
Create a regular Service instead
...hmmm...
aishwarya
ok
Mark M.
actually, you might not even need a service
aishwarya
thats cleaner
but how eaxctly
.
i would explain my requirement clearly:
Mark M.
...hmmmm...
with a static WakeLock, you could do something like this:
1. Have the BroadcastReceiver wake up with the alarm
aishwarya
i have three activities 1. morning_alarm 2. noon_alarm 3. night_alarm
Mark M.
2. In onReceive(), acquire the WakeLock, start the activity, and return, leaving the WakeLock acquired
3. When the activity starts, it releases the static WakeLock
10:10 AM
aishwarya
when morning_alarm does its work (i.e notifying the user to do something,) it sets an alarm using AlarmManager.setAlarm for the noon time with the intent as the noon_alarm activity
Mark M.
BTW, howdy, Calvin S!
aishwarya
ok
Mark M.
you probably should look at the Alarm Clock source code to see how they handle it, and follow their pattern
aishwarya
how do i wake up the braodcast reciever with the alarm?
Mark M.
via AlarmManager.setAlarm()
or, rather, AlarmManager#set()
that's covered in the book and in the Alarm sample app
though I use setRepeating() -- you'll just use set()
Calvin S.
Hi there!
aishwarya
thanks i will try that right now and get back to u in arnd 15 mins
Mark M.
ok, though the chat may be closed by then
Calvin: did you have a question?
Calvin S.
I was just dropping in to see how the Chat works
Mark M.
ok
anyone else have a question?
10:15 AM
Mike R.
I've got one more
Mark M.
go ahead
Mike R.
Some of my activities take a long time to start up (preparing data to display, reading database, etc.)
Old activity goes off screen and there is a black screen for a second or 2 until new activity is ready
is there a way to get something on screen while new activity completes onCreate?
Mark M.
Simple: don't do so much in onCreate()
do the bare minimum there, and use an AsyncTask or something to do the rest of the prep work off the main application thread
if there's nothing for you to display until that work is complete, show a ProgressDialog or something in onCreate(), then dismiss it in the AsyncTask's onPostExecute()
Mike R.
thanks
10:20 AM
NetApex
has left the room
Calvin S.
I have one
Mark M.
go ahead
Calvin S.
I am using the XmlPullParser
it works with an XML file with 1560 rows
but when I switch to one with 2080 rows it doesn't work
Mark M.
define "doesn't work"
Calvin S.
I didn't get a chance to see the exact message
aishwarya
hello can i ask 2 more questions? would ask when Mike is done.
ok
here i go
View paste
my first activity is a list say list of contacts. on clicking a contact it gives a new Activity with theme as Dialog giving u options to delete the contact and to go back. 
IF i click delete i delete the entry from db and finished this new dialog activity. but the list is not updated as it was not repopulated.
How to do i repopulate the list immediately (without starting the same activity again)
Mark M.
aishwarya: I will get to your questions when we are finished with Calvin's -- thanks!
Calvin: yeah, without an error message, I don't know what to tell you
aishwarya
ok
NetApex
has entered the room
Calvin S.
ok let me get the message
Mark M.
meanwhile, back to aishwarya
aishwarya: call requery() on your Cursor
that will automatically update your CursorAdapter, which will automatically update your ListView
10:25 AM
aishwarya
ok thanks
ow do i register my Application on a port for using SMS Manager.sendDataSMS
how*
Mark M.
beats me
I don't do much with SMS, in part because half of it is not available in the SDK
aishwarya
any pointers where i would find help regarding this?
i have tried posting it in many forums, no reply
:(
Mark M.
ummm...StackOverflow
aishwarya
will try thr too,hope someone knows exactly how to do that
.
btw generally speaking say without using SMSManager, how do i actually register my apps on a port in android
Calvin S.
I can't find an error in LogCat
Mark M.
aishwarya: there is no concept of "register my apps on a port in android"
Calvin: without knowing what "doesn't work" means, I can't really help you
there is no specific limit on the number of lines XmlPullParser can handle, AFAIK
Calvin S.
ok
10:30 AM
Justin M.
has left the room
Calvin S.
weird that I don't see a line number in the LogCat
or console in Eclipse
Mark M.
well, that's all the time for today's office hours
aishwarya
is there any way to touch the native SMS inbox of the android?
Mark M.
there will be two hours next week, though both will be in the evening (US Eastern Time), due to some online training I am teaching
Calvin S.
thanks
aishwarya
thanks
Mark M.
have a pleasant day!
NetApex
has left the room
Brian C.
has left the room
Mike R.
has left the room
aishwarya
has left the room
Calvin S.
has left the room
Mark M.
turned off guest access

Thursday, April 29

 

Office Hours

People in this transcript

  • aishwarya
  • Brian Cooley
  • Calvin Seto
  • Justin Munger
  • Mark Murphy
  • Mike Renda
  • NetApex