Office Hours — Today, April 5

Thursday, March 31

Apr 5
7:50 PM
Mark M.
has entered the room
7:55 PM
Mark M.
turned on guest access
Mark M.
turned off guest access
Mark M.
turned on guest access
8:00 PM
Suzanne A.
has entered the room
Suzanne A.
hey Mark
Mark M.
howdy, Suzanne!
Suzanne A.
Hallo! Danke!
I'm-a building my first fragment example
Mark M.
Berlin?
Suzanne A.
yessir
With a GridView of photos in the left pane, and soon one large photo in the right
Both fragments are subclasses of Fragment
What is the best way to pass the image index from the grid fragment to the photo fragment?
Mark M.
well, ideally, fragments don't talk directly to each other
after all, you might remix matters for other screen sizes, and so they might not both be in memory at once
Suzanne A.
okay. what is the best way to display the photo?
Mark M.
the way I approached it, following Ms. Hackborn's recommendation, was to have events flow from the fragment to the activity via a listener interface
Suzanne A.
oh. do you have an example?
Mark M.
the hosting activity will need to know how to get the event to the other fragment -- if they're both hosted by that same activity, that's easy, of course
hang on
from the latest _The Busy Coder's Guide to Android Development_ (Version 3.6, out for a week or so)
Suzanne A.
okay, got it
is there a specific place in EU4You6>
?
Marco G.
has entered the room
Marco G.
hello, can I ask a question?
8:05 PM
Mark M.
well, the EU4You activity will host the CountriesFragment and also the DetailsFragment for large screens
Marco G: please hold on a bit, while I get Suzanne squared away
Marco G.
Sorry, I'll wait my turn
Mark M.
Suzanne: when the user clicks a country in the CountriesFragment, it passes the URL to be displayed to the EU4You activity
in large/xlarge screens, that will trigger EU4You to call a method on DetailsFragment
in small/normal screens, that will trigger EU4You to start up a DetailsActivity which will hold the DetailsFragment
Suzanne A.
ah, onDetailsFragment
Mark M.
activities turn into an orchestration layer in Fragmentland
Suzanne A.
right. so I have to build the event handling mechanism ...
Mark M.
which is mostly an interface for the event, and having the activity implement that interface
so the event source fragment can let the activity know about the event, and the activity has to figure out how best to do that
Suzanne A.
okay. I'll look at DetailsActivity and DetailsFragment
Mark M.
both are pretty thin classes, IIRC
Suzanne A.
and CountryListener
thin is good at times like these :-)
8:10 PM
Mark M.
and your copy of the book is waiting your download
Suzanne A.
danke (again)
Mark M.
no problem
Marco: your turn!
or anyone with a question, at this point
Marco G.
I have to represent graphically a tree structure.. I've asked few days ago in android-developers mailinglist and i've got some replies, but I want also ask to you what do you think is the best way to do
Erdal
has entered the room
Marco G.
others have done it customizing expandablelistview
Mark M.
do you have a link to the android-developers discussion? I may as well catch up with that first
Marco G.
Mark M.
(btw, howdy, Erdal!)
Erdal
hey guys!
hey Mark
can we just ask our questions here?
Marco G.
I would ask to you if there is something like a multi levels textview in the APIs (just like a file manager) or if i have to implements this levels
*these
Mark M.
Erdal: I'm on a lousy connection, so I'm trying to tackle questions one at a time
Erdal
sure
Mark M.
well, to be honest, I think the right answer is not to do it
your example of a file manager, I would do one ListActivity to represent a directory
showing its folders and files
clicking on a folder would open up a ListActivity on it
8:15 PM
Mark M.
in a Honeycomb style, if you do it via fragments, you can choose to have a nice flow, akin to Finder in OS X
8:15 PM
Mark M.
yet still have something finger-friendly on phones
I am not a big fan of tree structures on phone screens
As TreKing put it, "You probably don't want to nest too deeply anyway considering the screen limitations on mobile devices. "
Marco G.
the file manager was a generic tree structure example, I was wondering if there is something that can feed my tree and output such structure with listviews or similar
Mark M.
not really
I think that android-developers thread covered the ground fairly well
Marco G.
so you suggest to do a ListActivity or something for each tree level and implements the navigation?
fitz
has entered the room
Mark M.
if I were starting from scratch today, I would use ListFragments, to make it easier to do something nice on tablets
but, yes, ListActivity or ListFragments would be my approach
Marco G.
ok, I'll ask if we can go straight to honeycomb.. but i don't think so.. I must take a look to compatibility library also
thank you Mark
Mark M.
yes, the compatibility library should cover this
Erdal: your turn!
Marco G.
oh great
Mark M.
(btw, howdy, fitz!)
fitz
Howdy :)
Erdal
thanks
I'm working on an IM app
8:20 PM
Erdal
I have a Service that tries to maintain a TCP connection to my server
now everything seems to work fine until the phone goes to a hard sleep I think
I am trying to acquire a partial cpu wake lock
and release it when waiting for data
a normal log looks something like this:
View paste
04-05 09:43:06.561 D/WifiService( 1089): acquireWifiLockLocked: WifiLock{IMO wifi lock type=1 binder=android.os.BinderProxy@44ae0748}
then I process data inside my app
and then
View paste
 04-05 09:43:06.569 D/WifiService( 1089): releaseWifiLockLocked: WifiLock{IMO wifi lock type=1 binder=android.os.BinderProxy@44ae0748}
but then the phone goes to deep sleep (I think) I see this in the logs
View paste (10 more lines)
04-05 09:40:14.178 D/WifiService( 1089): acquireWifiLockLocked: WifiLock{IMO wifi lock type=1 binder=android.os.BinderProxy@44ae0748}
04-05 09:40:14.194 D/WifiService( 1089): releaseWifiLockLocked: WifiLock{IMO wifi lock type=1 binder=android.os.BinderProxy@44ae0748}
04-05 09:42:15.663 D/WifiService( 1089): acquireWifiLockLocked: WifiLock{IMO wifi lock type=1 binder=android.os.BinderProxy@44ae0748}
04-05 09:42:15.671 D/WifiService( 1089): releaseWifiLockLocked: WifiLock{IMO wifi lock type=1 binder=android.os.BinderProxy@44ae0748}
04-05 09:42:25.569 D/WifiService( 1089): acquireWifiLockLocked: WifiLock{IMO wifi lock type=1 binder=android.os.BinderProxy@44ae0748}
04-05 09:42:25.569 D/WifiService( 1089): releaseWifiLockLocked: WifiLock{IMO wifi lock type=1 binder=android.os.BinderProxy@44ae0748}
04-05 09:42:26.702 D/WifiService( 1089): acquireWifiLockLocked: WifiLock{IMO wifi lock type=1 binder=android.os.BinderProxy@44ae0748}
04-05 09:42:26.717 D/WifiService( 1089): releaseWifiLockLocked: WifiLock{IMO wifi lock type=1 binder=android.os.BinderProxy@44ae0748}
04-05 09:42:27.202 D/WifiService( 1089): acquireWifiLockLocked: WifiLock{IMO wifi lock type=1 binder=android.os.BinderProxy@44ae
...
...
notice the interval is every 5 mins which is the same as my keep alive interval
but the weird thing is I don't see any other logs coming from my app
Mark M.
the interval is not every 5 minus
er, minutes
at least not in that log segment
some are little more than a second apart
Erdal
hm you're right
sometimes it was
yes
you're right sometimes it is very close
fitz
Mark have you started to use IntelliJ yet? I get your examples to run in Eclipse and having a bit of a time getting the examples to run i IntelliJ - do you know if IntelliJ runs Motorola plugins? that is next on to-do.... to long of a list ahhh - I need to jet so just answer me direct via email or here and I will check these notes later tonight thanks
8:25 PM
fitz
has left the room
Mark M.
Erdal: I really don't recommend that you try to keep the WiFi connection
hard on the battery
Erdal
actually I am acquiring a cpu wake lock
but the log says Wifi for some reason
I do this:
View paste
final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
				"IMO partial wake lock");
wakeLock.setReferenceCounted(true);
I also have a wifi lock that I hold while sending
Mark M.
actually, you're not acquiring the WakeLock in that code snippet
you need to call acquire()
and, later, call release()
Erdal
yes I do
that is just the setup
8:30 PM
Mark M.
it would seem to make sense that your WifiLock is what is causing the WifiLock log entries
Marco G.
has left the room
Erdal
yes
I will double check that
but my alarms aren't firing either
I used the wakeup one
for sendig keep alives
Mark M.
are you sure that they're not firing, or just that your results are not happening?
what sort of PendingIntent are you using for the alarms?
Erdal
View paste
		final Intent intent = new Intent(context, Alarms.class)
				.setAction(action);
		final PendingIntent pi = PendingIntent.getBroadcast(context, -1,
				intent, PendingIntent.FLAG_CANCEL_CURRENT);
I have a class called Alarms
it's registered in the manifest as a receiver
Mark M.
have you put in logging statements to confirm if onReceive() of Alarms is getting control on your scheduled times?
Erdal
yes
I have a log in onReceive
I see that log usually, but not when the phone goes to sleep
I think it is sleeping
there is no good way of knowing when the phone will go to sleep afaik
Mark M.
can you show me your call to setRepeating()?
8:35 PM
Erdal
sure the whole method is this
View paste (3 more lines)
	public static void scheduleAlarm(final String action, final long delay,
			final boolean repeating) {
		// IMOLOG.i(TAG, "Scheduling alarm : " + action + " for "
		// + (delay / 1000.0) + " seconds from now; repeating: "
		// + repeating);
		final long triggerAtTime = SystemClock.elapsedRealtime() + delay;
		final Intent intent = new Intent(context, Alarms.class)
				.setAction(action);
		final PendingIntent pi = PendingIntent.getBroadcast(context, -1,
				intent, PendingIntent.FLAG_CANCEL_CURRENT);

		if (repeating) {
			am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
					triggerAtTime, delay, pi);
		} else {
...
Mark M.
and you'
and you're sure that repeating is true?
Erdal
yes because I call it like this
View paste
public static void scheduleRepeatingAlarm(final String action,
			final long delay) {
		scheduleAlarm(action, delay, true);
	}
Mark M.
then I don't know what to tell you
nothing seems out of place
Erdal
yea it's very strange
but when the phone goes to deep sleep the logs should still appear right?
it's not like logging is disabled when that happens??
Mark M.
well, nothing should appear until the phone wakes up due to the alarm
Erdal
yes during the alarm
Mark M.
that's the whole point of sleep mode
once the alarm goes off, everything in onReceive() of Alarms runs under a WakeLock managed by AlarmManager
Erdal
yes
Mark M.
if you acquire your own WakeLock in that period, you can keep the device awake past onReceive() -- this is what I do in WakefulIntentService
Erdal
at the top of onReceive I have a log
yes I saw that one
pretty useful
because I wasn't acquiring one
before calling startService
and so after that I thought I solved my problems
but something is still not right
8:40 PM
Mark M.
again, I don't know what to tell you
sorry!
Suzanne A.
may I ask another question?
Mark M.
you're still awake?
Suzanne A.
yessir
Mark M.
but go right ahead!
Erdal
actually reading this:
If your application wants to allow the delivery times to drift in order to guarantee that at least a certain time interval always elapses between alarms, then the approach to take is to use one-time alarms, scheduling the next one yourself when handling each alarm delivery.
from the AlarmManager class
Suzanne A.
best practices for downloading large numbers of images from the web effectively?
Erdal
maybe my alarms are drifting
and so I should use one-time alarms that schedule the next ones
Mark M.
Suzanne: best practices in terms of what?
Suzanne A.
how to optimize performance?
or is this question too vague?
Mark M.
Suzanne: it's a little vague, yes.
performance in terms of CPU? RAM? Bandwidth?
Erdal: I doubt that's your problem
Suzanne A.
ah, I'd probably say cpu
Mark M.
does the download need to continue even if the user bails out of the activity?
Suzanne A.
for this question, i'd say no
8:45 PM
Mark M.
OK, then it sounds like an AsyncTask, or possibly several
right now, AsyncTask works off of a thread pool, so you could try downloading some simultaneously
Suzanne A.
oh good, a thread pool - that helps me
Mark M.
you'd have to experiment to see when too many background threads start to drag things down, though
Suzanne A.
okay, will do
thanks, mark - see you soon
Suzanne A.
has left the room
Mark M.
replies to fitz' queued up questions: no I have not experimented with importing my projects into IDEA 10, and IDEA 10 does not run the MOTODEV Studio plugins, as they are Eclipse-specific
feel free to ask on the [cw-android] Google Group with respect to the IDEA 10 import problems -- without symptoms, I can't provide advice
any other questions?
8:55 PM
Mark M.
ok, well, have a pleasant day!
Erdal
has left the room
Mark M.
turned off guest access

Thursday, March 31

 

Office Hours

People in this transcript

  • Erdal
  • fitz
  • Marco Grassi
  • Mark Murphy
  • Suzanne Alexandra