Office Hours — Today, April 26

Thursday, April 21

Apr 26
3:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Julius
has entered the room
Mark M.
howdy, Julius!
Julius
Hello
how are you today?
Mark M.
OK, and you?
Julius
good - just awake :)
still hoping to bump into you at IO
Mark M.
well, I should be there
along with thousands of others
Julius
:)
I was wondering if you had any advice on applying a font to TextViews throughout an application
(once marketing guys get hold of an app... :)
Mark M.
there's no good way to do it
you have to do it in Java code
neither layout XML nor styles/themes help here
4:00 PM
Mark M.
very annoying
you could write yourself a utility method that walks a View's children, identifies those that inherit from TextView, and updates the typeface
but you'd need to remember to apply that everywhere (each activity, each row in a ListView, etc.)
Julius
(bugger)
Mark M.
ah
Julius
I recently did all the EditText's styles which was great
Mark M.
I was trying to determine the connection there
yeah, I have no idea why they haven't done something in the XML for this
Julius
err modifie dthe style and that was great
across the whole app was really nice
hmm cool
Mark M.
another possibility is that you can read in the layout XML files yourself and add your own attributes that point you to font files touse
Julius
just checking I couldn't do it easily
Mark M.
er, to use
and please read the Fonts chapter in The Busy Coder's Guide to Android Development, particularly the part about ellipsize
Julius
oh right ok
Mark M.
I just answered a StackOverflow question pertaining to that issue
Julius
yeah I wondered whether ellipsize slows down list scrolling
Ahmet
has entered the room
Julius
that's just a total aside
Mark M.
I doubt that it speeds it up :-)
howdy, Ahmet!
Julius
thanks I'll look into that chapter
Mark M.
Ahmet: do you have a question?
Ahmet
I am good, thanks how about you?
yes
Don
has entered the room
Ahmet
I have a general question
Don
Hi everyone
fitz
has entered the room
Mark M.
Ahmet: go ahead
(btw, howdy, Don and fitz!)
Ahmet
whats the best way to handle runtime changes on certain conditions?
4:05 PM
fitz
hello - observing today :)
Mark M.
I do not know what you mean by "runtime changes on certain conditions"
(fitz: if you were observing tomorrow, I'd ask what the lottery numbers were going to be)
Ahmet
for example, screen rotation or a phone call
Mark M.
Ahmet: those are fairly distinct events
Ahmet
a phone call is not considered as a runtime change?
right
Mark M.
you're the one coming up with the "runtime change" term, not I
fitz
go with #'s that end in 1 and 2's
Mark M.
a screen rotation is a configuration change
you handle it via onSaveInstanceState() and onRetainNonConfigurationInstance(), except in relatively unusual circumstances
Julius
(I'm observing tomorrow)
Mark M.
there's a chapter in The Busy Coder's Guide to Android Development on rotation
a phone call is simply the current activity being paused and stopped
it might be destroyed eventually, if the user does not come back for a long time
you can get control in onPause(), onStop(), and onDestroy() to do whatever bookkeeping you want
that's covered in the activity lifecycle chapter of The Busy Coder's Guide to Android Development
Don
I have a question when Ahmet is finished.
Ahmet
thanks but is it onpause/onresume or onstop/oncreate? or should we do it in both?
4:10 PM
Mark M.
the counterpart to onStop() is onStart(), not onCreate()
the difference between onStop/onStart and onPause/onResume is relatively obscure, so you can use whichever pair you wish
Ahmet
ok onstop/onstart.
Mark M.
more often, people use onPause/onResume
let me take some questions from others, and then I will cycle back around to you
Ahmet
ok
fitz
has left the room
Mark M.
Don: fire away!
fitz
has entered the room
Don
I get errors when trying to compile EU4You_6. Anything having to do with the ACL produces an error.
Mark M.
what sort of error?
Don
View paste

The import android.support cannot be resolved	CountriesFragment.java	/EU4You_6/src/com/commonsware/android/eu4you	line 17	Java Problem
Mark M.
you need to have the ACL JAR in libs/ and, if you're using Eclipse, in your build path
Don
That is probably the culprit. But I'm getting over 100 errors.
I have the ACL jar
Mark M.
the compiler does not think so
4:15 PM
Don
View paste
dhcp-don-sd-mbp-2b: cw-android (master)$ cd Fragments
dhcp-don-sd-mbp-2b: Fragments (master)$ ls
EU4You_6
dhcp-don-sd-mbp-2b: Fragments (master)$ cd EU4You_6/
dhcp-don-sd-mbp-2b: EU4You_6 (master)$ cd libs
dhcp-don-sd-mbp-2b: libs (master)$ ls
android-support-v4.jar
dhcp-don-sd-mbp-2b: libs (master)$ ls -l
total 208
-rw-r--r--  1 donm  staff  103381 Apr 13 15:05 android-support-v4.jar
dhcp-don-sd-mbp-2b: libs (master)$
Mark M.
are you compiling with Ant or Eclipse?
Don
Eclipse
Mark M.
did you add it to your build path in Eclipse?
Don
No. Where is that done?
Mark M.
Project properties
in the Build Path area, there's a Libraries tab IIRC
on there, there's an Add JAR button
that will bring up a dialog to allow you to navigate the files in your project and find the JAR
Julius
(select project, Alt Enter => Java Build Path => Libraries tab => Add External Jars...
Mark M.
I wouldn't use Add External JARs
Julius
oh... :)
Mark M.
Add JAR is what I have my students use, and it seems to work
Julius
oh
what's the difference?
Mark M.
I seem to recall problems with Add External JAR when the JAR is in your libs/
Julius
oh I see
Mark M.
IIRC, Add External JAR lets you browse the whole filesystem
Julius
I haven't had any issues, but good to learn soething new
Mark M.
there used to be a problem
might be cleared up now
Julius
oh right yeah I tend to share libs across projects
4:20 PM
Julius
especially the cwac ones
:)
(sorry to butt in)
Don
That got rid of some of the errors. Specifically the ones having to do with Fragments.
But, I'm getting a lot of
View paste
Description	Resource	Path	Location	Type
R cannot be resolved to a variable	CountriesFragment.java	/EU4You_6/src/com/commonsware/android/eu4you	line 34	Java Problem
Mark M.
Project | Clean from the main menu
and if that does not help, check your console for resource-related problems
Don
Didn't help. No entries in Concole
Mark M.
Can't help you much
R is automatically generated
Don
ok, I know about R. Will Google for it.
Mark M.
you will need to figure out why it is being generated in the wrong package or what is blocking it from being generated
I'll swing back to you in a bit
fitz: the "better medium" (per your email) *is* office hours, or StackOverflow, or the android-developers Google Group
AngelOD
has entered the room
Mark M.
I have examples of using ContactsContract and multiple columns in The Busy Coder's Guide to Advanced Android Development
4:25 PM
Mark M.
howdy, AngelOD!
fitz
Mark quick one - NFC only works when 4CM away from each other - is this correct? so what process would be best for devices 2-3-5 feet away?
AngelOD
Greetings :)
Mark M.
fitz: I don't know the range for NFC
Bluetooth is good for 2-3-5 feet away
navjeet
has entered the room
Mark M.
or possibly NFC and a Pringles can
:-)
fitz
great will lok at advanced book again - any page or section?
Mark M.
there's a chapter on contacts
fitz
ok
thanks
Mark M.
Chapter 17, to be precise
howdy, navjeet!
AngelOD: do you have a question?
navjeet
what is best way to subscribe/watch for bluetooth paring events?
pairing
AngelOD
I do, yes. Shall start typing it out. :)
Mark M.
navjeet: beats me, I have not done much with Bluetooth
navjeet: I try to take questions one at a time, so I'll be back to you again for an additional question in a bit, once I give others a turn
Don
has left the room
navjeet
ok
Mark M.
AngelOD: go ahead
AngelOD
I've been experimenting a bit with services and broadcast events and such, and I know how to make it start up with the device, but I'm wondering how to best handle the case of installing and updating, and ensuring that the broadcast is registered without having to reboot the device, as well as ensuring it isn't registered multiple times (as I understand that's actually possible?).
4:30 PM
Mark M.
taking those in order...
installing/updating: I'm not sure what your concern is, precisely
registered multiple times: a manifest-registered BroadcastReceiver will only be in there once
AngelOD
Hold on.. Let me look through my code. You can talk to someone else in the meantime. Let me see if I can't find a better way to ask. :)
Mark M.
OK
Julius: do you have another question?
Julius
yes
I know you don't use Eclipse but... I have some Widgets that Eclipse doesn't handle well and recommends using: View.isInEditMode(). I'm not sure how to go about using this or where should I put it so I can continue to use the Graphical Layout editor in Eclipse. Have you managed to get around this before?
Mark M.
I haven't touched the graphical layout editor
Julius
heh ok thanks
Mark M.
that's a latter-half-of-2011 project
Julius
:)
Mark M.
sorry
Julius
np
Mark M.
Ahmet: do you have another question?
Ahmet
yes.
4:35 PM
Mark M.
Ahmet: go ahead
Ahmet
where to handle incoming call interrupts? onpause/onresume?
does a call kill our activity?
Mark M.
An incoming phone call will pause and stop your activity
the activity may later get destroyed, if the call goes on for a long time and Android needs the memory
as to "where to handle incoming call interrupts", you are thinking about it the wrong way, IMHO
lots of things cause activities to be paused and stopped
- User presses HOMe
(er, HOME)
- User chooses a Notification from the notification drawer
- User places a phone call
Ahmet
yes
Mark M.
Think of it less as "incoming phone call" and "another activity taking over the foreground"
onPause/onResume are the typical pair for events related to this, where you need them
Ahmet
ok
Mark M.
fitz: do you have another question?
gonna take that as a "no"
AngelOD: do you have another question?
4:40 PM
fitz
no I am good thanks
Ahmet
I have one
Mark M.
Ahmet: hold on
Ahmet
ok
Mark M.
navjeet: do you have another question?
Julius: do you have another question?
Julius
yes
navjeet
one more on bluetooth
Julius
have you seen any documentation on adding Application Widgets to the locked screen?
(I can wait)
Mark M.
navjeet: again, I have not worked with Bluetooth
you will need to ask Bluetooth-related questions on StackOverflow, the android-developers Google Group, etc.
Julius: there is no support for app widgets/RemoteViews on the lock screen, though there is a proposal on the table for it
wouldn't shock me to see it early next year
Julius
when you say no support...
I guess I have seen it in a few apps
navjeet
did some googling on bluetoth and found some ideas on using intent android.bluetooth.intent.action.BONDING_CREATED and BroadcastReciever might help in what I am trying to do. Do you have any thoughts on that?
Julius
(not trying to be difficult)
Mark M.
navjeet: you will need to ask Bluetooth-related questions on StackOverflow, the android-developers Google Group, etc.
4:45 PM
Mark M.
Julius: you are probably seeing something like a window over top of the lock screen or some other crap like that
Julius
:D
heh ok
Mark M.
the lock screen itself cannot be replaced or modified
navjeet
ok
Julius
ok thank you again
Mark M.
that's part of the reason why there is discussion of allowing the user to add an app widget or the equivalent -- it's one way of exposing functionality cleanly to the lock screen without compromising security
Ahmet: do you have another question?
Ahmet
yes.
I am unzipping a big file in an AsyncTask, it is showing a progress dialog, all is ok but
navjeet
has left the room
Ahmet
when another activity takes over the foreground, the zipping in the AsyncTask does not continue and the app crashes when you try to return to the activity again
Mark M.
well, the background thread of AsyncTask will continue to run
Ahmet
I want it to continue in the background
Mark M.
so I feel reasonably confident that your unzipping is continuing
in terms of the app crashing -- what is the exception?
Ahmet
let me check it
Mark M.
meanwhile, if anyone has any remaining questions, go ahead and chime in
Ahmet
.lang.IllegalArgumentException: View not attached to window manager
on dialog
Mark M.
this is probably from your progress dialog
4:50 PM
Ahmet
yes
4:50 PM
Mark M.
I don't use ProgressDialog much
I think you may be trying to communicate with a dead dialog or something
make sure this is a managed dialog, or otherwise arrange to have a fresh one in onResume() or something
Ahmet
if I handle the dialog in onpause/onresume, will the zipping continue in the background?
Mark M.
also, search StackOverflow, as I am sure this question has come up there before
Ahmet
or do I have to handle the zipping, too?
Mark M.
the zipping is independent of the dialog
again, the background thread of your AsyncTask should be oblivious to what is going on in the activity
the zipping should be continuing regardless
Ahmet
ok, thanks. I will try it.
AngelOD
Right. For when you have time. :) I have the OnBootReceiver registered, which will ensure that the service starts up when the device is rebooted. But how can I make sure that the service starts up when they install/update the application?
Mark M.
it won't start up when they install the application
that is by design
fitz
has left the room
Mark M.
ideally, you don't start a service at boot time
few services need to run all the time
ideally, at boot time, you are setting up alarms for AlarmManager
AngelOD
So what's the best practice in this case? Can I check if it's already running, and then start it up upon app start if it isn't?
Mike R.
has entered the room
Mark M.
regardless, for doing boot-time things after install, keep a flag in a SharedPreference or something to detect whether you have been run before
Julius
has left the room
Mark M.
in terms of an update, you can watch for the ACTION_PACKAGE_REPLACED broadcast, IIRC
Mike R.
howdy
AngelOD
That's what it does, using the WakefulIntentService component.
Mark M.
right
so, you would set up your alarm schedule in a boot-time receiver and the first time an activity is run in your app
4:55 PM
Mark M.
an easy spot to put that logic is in a custom Application class, so it won't matter what activity they first visit, if there might be more than one for some reason
and, you would also set up the alarm schedule if you have been upgraded when you get the ACTION_PACKAGE_REPLACED for your package
one of these days, I'll elaborate on these items in the books
Mike R: only a few minutes left -- do you have a quick question?
Mike R.
Probably take some time. When's the next one?
Mark M.
Thursday
7:30pm Eastern
AngelOD
Aah okay. Thanks. :) I'll look into it. If I can't figure it out, I'll come back next time, with a better formulated question and code and such. Had an incident with a sick cat in the middle of it all. Hence the delay. :)
Mark M.
next East Coast business hours ones are next week
Mike R.
see you thursday
Mark M.
AngelOD: I hope your cat gets to feeling better
AngelOD
Mark: Thanks. :)
Mike R.
has left the room
Mark M.
any last questions?
AngelOD
Not from me. :)
Mark M.
OK, that wraps up today's chat
5:00 PM
Mark M.
as noted, the next chat is Thursday, 7:30pm Eastern Time
have a pleasant day, all!
Ahmet
has left the room
AngelOD
has left the room
Mark M.
turned off guest access

Thursday, April 21

 

Office Hours

People in this transcript

  • Ahmet
  • AngelOD
  • Don
  • fitz
  • Julius
  • Mark Murphy
  • Mike Renda
  • navjeet