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 :-)
|
Justin M. |
Just two questions for you today whenever you're ready
|
May 7 | 9:30 AM |
Mark M. |
fire away
|
Justin M. |
Cool, these are more general best practice type questions...
|
Justin M. |
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...
|
Justin M. |
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
|
Mark M. |
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
|
Justin M. |
Gotcha
|
Mark M. |
easy to access the resources without worrying about having the wrong ones
|
Justin M. |
OK, cool deal
|
Justin M. |
Here's the second question...
|
May 7 | 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...
|
May 7 | 9:35 AM |
Mark M. |
Eye-fone?
|
Mark M. |
:-)
|
Justin M. |
I'm wondering if that's really necessary to do since the OS handles the stack of intents/activities for you already?
|
Justin M. |
LOL, yeah ;-)
|
NetApex | has entered the room |
Mark M. |
I would not create a traffic cop app, personally
|
Mark M. |
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!
|
Mark M. |
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.
|
Brian C. |
In the navigation based app, you push view controllers onto a stack
|
May 7 | 9:40 AM |
Brian C. |
I am mapping that to Android Activities called via Intents
|
Brian C. |
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
|
Brian C. |
i like it that way because of the back button
|
Mark M. |
moreover, it's the expected model for most things
|
Mark M. |
right
|
Mark M. |
it helps if you think of building your Android app as if it were a Web app
|
Mark M. |
activity = link to the next page of the Web app
|
Mark M. |
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
|
Brian C. |
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
|
Brian C. |
ah, good point
|
Brian C. |
ok, i'm good. thanks, mark
|
Mark M. |
NetApex: did you have a question?
|
Mark M. |
or, does anyone have a question?
|
Mike R. |
Mark, I've got a few
|
May 7 | 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
|
Mark M. |
I am riding one right now
|
Mark M. |
...oh, wait...
|
Mark M. |
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?
|
Mike R. |
I'll just ignore your attempts at humor for the moment.
|
Mark M. |
wow, tough crowd
|
Mark M. |
anyway
|
Mark M. |
when BACK is pushed, onPause() and onStop() are called, in that order
|
Mark M. |
and onSaveInstanceState() is called in there as well
|
Mark M. |
when HOME is pushed, the same thing happens
|
Mark M. |
whoops
|
Mark M. |
BACK also gets onDestroy() called, after onStop()
|
Mark M. |
onSaveInstanceState() should be called around when onPause() is called, but it's not exactly deterministic
|
Mark M. |
so:
|
Mark M. |
BACK = onPause() -> onStop() -> onDestroy(), plus onSaveInstanceState()
|
Mark M. |
HOME = onPause() -> onStop(), plus onSaveInstanceState()
|
Mark M. |
that's what happens right away, in any case, by default, for those buttons
|
May 7 | 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
|
Mark M. |
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
|
Mark M. |
use onPause() for setResult()
|
Mike R. |
ok I'll try that
|
Mike R. |
Now. ListViews
|
Mike R. |
trying to understand on to refresh a listview when the data changes
|
May 7 | 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
|
Mark M. |
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.
|
Mike R. |
but it's kind of pokey.
|
Mark M. |
That shouldn't be needed
|
Mark M. |
However, ArrayAdapter is not really designed for some sort of shared array as the backing store
|
Mark M. |
More designed for use within a single activity
|
Mark M. |
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
|
Mark M. |
that'll be more efficient than trying to sync a HashMap and an ArrayAdapter
|
Mark M. |
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
|
Mark M. |
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?
|
May 7 | 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
|
Mark M. |
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?
|
Mark M. |
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
|
aishwarya |
that i need to start an activity immediately after waking up the device
|
aishwarya |
.
|
Mark M. |
that is very unwise
|
Mark M. |
to the point of being unacceptable
|
aishwarya |
the problem is that it does wake the device often , but not always
|
aishwarya |
why so?
|
aishwarya |
my app is like an alarm clock
|
Mark M. |
oh wait, sorry
|
Mark M. |
my mistake
|
Mark M. |
I was thinking you meant you wanted to pop up an activity immediately after a reboot
|
aishwarya | |
aishwarya |
noo
|
Mark M. |
(wow, three days in Europe and my brain turns to mush...)
|
Mark M. |
you are going to need to grab the WakeLock in the BroadcastReceiver
|
Mark M. |
like the WakefulIntentService samples show
|
Mark M. |
Otherwise, the phone may fall asleep after onReceive() returns and before you get a chance to grab a WakeLock in your service
|
May 7 | 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
|
Mark M. |
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
|
Mark M. |
For your case, I would recommend not using WakefulIntentService
|
Mark M. |
Create a regular Service instead
|
Mark M. |
...hmmm...
|
aishwarya |
ok
|
Mark M. |
actually, you might not even need a service
|
aishwarya |
thats cleaner
|
aishwarya |
but how eaxctly
|
aishwarya |
.
|
aishwarya |
i would explain my requirement clearly:
|
Mark M. |
...hmmmm...
|
Mark M. |
with a static WakeLock, you could do something like this:
|
Mark M. |
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
|
Mark M. |
3. When the activity starts, it releases the static WakeLock
|
May 7 | 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()
|
Mark M. |
or, rather, AlarmManager#set()
|
Mark M. |
that's covered in the book and in the Alarm sample app
|
Mark M. |
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
|
Mark M. |
Calvin: did you have a question?
|
Calvin S. |
I was just dropping in to see how the Chat works
|
Mark M. |
ok
|
Mark M. |
anyone else have a question?
|
May 7 | 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.)
|
Mike R. |
Old activity goes off screen and there is a black screen for a second or 2 until new activity is ready
|
Mike R. |
is there a way to get something on screen while new activity completes onCreate?
|
Mark M. |
Simple: don't do so much in onCreate()
|
Mark M. |
do the bare minimum there, and use an AsyncTask or something to do the rest of the prep work off the main application thread
|
Mark M. |
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
|
May 7 | 10:20 AM |
NetApex | has left the room |
Calvin S. |
I have one
|
Mark M. |
go ahead
|
Calvin S. |
I am using the XmlPullParser
|
Calvin S. |
it works with an XML file with 1560 rows
|
Calvin S. |
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.
|
aishwarya |
ok
|
aishwarya |
here i go
|
aishwarya |
View paste
|
Mark M. |
aishwarya: I will get to your questions when we are finished with Calvin's -- thanks!
|
Mark M. |
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
|
Mark M. |
aishwarya: call requery() on your Cursor
|
Mark M. |
that will automatically update your CursorAdapter, which will automatically update your ListView
|
May 7 | 10:25 AM |
aishwarya |
ok thanks
|
aishwarya |
ow do i register my Application on a port for using SMS Manager.sendDataSMS
|
aishwarya |
how*
|
Mark M. |
beats me
|
Mark M. |
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?
|
aishwarya |
i have tried posting it in many forums, no reply
|
aishwarya |
:(
|
Mark M. |
ummm...StackOverflow
|
aishwarya |
will try thr too,hope someone knows exactly how to do that
|
aishwarya |
.
|
aishwarya |
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"
|
Mark M. |
Calvin: without knowing what "doesn't work" means, I can't really help you
|
Mark M. |
there is no specific limit on the number of lines XmlPullParser can handle, AFAIK
|
Calvin S. |
ok
|
May 7 | 10:30 AM |
Justin M. | has left the room |
Calvin S. |
weird that I don't see a line number in the LogCat
|
Calvin S. |
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 |