Office Hours — Today, September 21

Friday, September 17

Sep 21
7:50 PM
Mark M.
has entered the room
7:55 PM
Mark M.
turned on guest access
Evan
has entered the room
Mark M.
howdy, Evan!
Evan
Hey Mark :-)
Mark M.
how can I help you today?
Evan
i'm pulling my hair out trying to get focus to be managed properly in my subclass of AdapterView....
Mark M.
oy
that doesn't sound pleasant
Evan
I'm trying to essentially define for my composite widget, a hook that will allow me to decide which child to focus. It will usually seem to decide for me, and my override of requestChildFocus gets called, but this is too late...
not sure if I'm phrasing this quite right... but
is there some callback that i can define that will allow me to answer the question of which child widget to give focus when focus propagates down to my composite widget?
8:00 PM
Mark M.
I can tell you that, outside of the focus-related attributes in layout XML, I haven't played with focus stuff at all
Chris
has entered the room
Mike R.
has entered the room
Evan
hmm... okay :-/ I've tried overriding ViewGroup's void requestFocus(int direction, Rect previouslyFocused) but it never gets called... instead, requestChildFocus gets called.
Mike R.
Hello
Mark M.
are you using addFocusables()?
(btw, howdy, Chris and Mike R!)
Chris
Hi. I have some newbie questions :)
Mark M.
hang on Chris -- I'll get to your question shortly
Evan
i haven't tried that... but calling setFocusable(true) on the AdapterView doesn't seem to cause my AdapterView's overridden requestFocus to get called when focus is propogated down to the widget... (which i would have assumed would be called before any of hte child widgets were to receive focus)
Mark M.
yeah, focus looks really messy
8:05 PM
David
has entered the room
Mark M.
you might try to track down the implementation of focusSearch() in the source code and see if that gives you any clues
I'm not quite sure what else to tell you at this juncture
Evan
okay... thanks!
Mark M.
(btw, howdy, David -- you're after Chris and Mike R in the queue)
David
Hi.
Mark M.
Chris: you're turn -- got a question?
er, that's "your turn"...
Chris
My question is in regards to a test program I made that uses the technique of binding to a service as in Patchy (Android Tutorials 2.9 chapter 30). I want to be in my main activity and test whether it is currently bound to a service or not. In IBinder, I found isBinderAlive() (Check to see if the process that the binder is in is still alive.). I'm not sure if this is what I should be using, and if so, I can't figure out how to use it. I think I've found a way around it, but for a while my app was crashing when I rotated the screen w/o the service being bound yet because in onDestroy() I had unbindService(svcConn). I need to read more about the application lifecycle.
Mark M.
you know if you are bound to a service because of the existence of the IBinder
you use it in onServiceConnected() (e.g., cast to the proper type and store it in a data member)
you drop it in onServiceDisconnected() (e.g., null out the data member)
Chris
Oh OK.
Mark M.
then the question of "am I bound" is "is my data member not null?"
Chris
Yeah. Cool, thanks :)
Easy one for you.
Mark M.
certainly easier than Evan's focus problem... :-)
OK...Mike, got a question?
Evan
heh... i've been struggling with these for a while.
Mike R.
Got some questions regarding crash reports I've been getting.
First one seems straightforward, but can't seem to see the problem
View paste
java.lang.NullPointerException
at com.medpagetoday.medpage.Database.readArticleIDs(Database.java:183)
at com.medpagetoday.medpage.MedpageService$6.run(MedpageService.java:801)
at java.lang.Thread.run(Thread.java:1096)
that pretty much the whole crash log.
8:10 PM
Mark M.
OK, what does like 183 of Database.java look like?
(er, line 183)
Mike R.
View paste (6 more lines)
synchronized Collection<String> readArticleIDs() {				// this returns an array of all article ids in the articles table
		Collection<String> ids = new ArrayList<String>();		// used to determine which articles to purge from database
		String sql = "SELECT tbid FROM articles";
		try {
			Cursor articleCursor = db.rawQuery(sql, null);
			articleCursor.moveToFirst();
			while (!articleCursor.isAfterLast()) {
				String id = (articleCursor.getString(0));
				ids.add(id);
				articleCursor.moveToNext();
			}
			articleCursor.close();
		}
		catch (SQLException s) {
			Log.e("ReadArticleIDs", s.getLocalizedMessage());
...
I just can't see where something in here can be null.
Mark M.
which of those is line 183?
Mike R.
Well, the code has been changed since uploading, but I think 183 is the creation of the 'ids' variable
Mark M.
uh, yeah, that hardly seems possible
Mike R.
at any rate, this is the method referenced in the stack trace
Mark M.
for issues like this, using version control and tags will be essential
most likely, db is null
it's about the only thing you're referring to that is not self-contained within the method
Mike R.
Not sure how it could be. this method gets invoked as part of a whole chain of database calls
db gets assigned in the onCreate().
my mistake. it gets assigned in the class constructor.
Mark M.
another conceivable problem would be if SQLException doesn't really support getLocalizedMessage()
oh, wait, no
that would give a NullPointerException inside of Log somewhere
8:15 PM
Mark M.
well, short of you magically coming up with the version of the method that is in your shipping code, the only thing I see that could be null is db
even if that seems improbable
but, again, if you want to make sense of production stack traces, ya gotta keep a copy of the source code that aligns with the production APK
Mike R.
ok
Mark M.
let me swing back to you in a bit for your next stack trace and let the others have a shot
David: got a question?
Mike R.
you bet
Evan
i've also got another Q when you're ready for me ;-)
David
View paste
I have a cooking video site cookinworld.com built on Drupal.
I am trying to make an Android app based on this site.
What do I need for Android to retrieve data from my website?
This is how it works: 
A user enters parameters like cuisine and dish type. 
Then, Android displays a list of recipes. The user clicks a receipe
then the 3rd screen displays video/picture and cooking instructions.
Mark M.
well, I don't know much about Drupal
either it has a Web service API that supports the operations you want, or it doesn't
if it does, you'd use it
if it doesn't, you might be able to fake if if your "parameters like cuisine and dish type" can somehow be converted into some request that gives you a custom feed or something
and if that's not an option, you'd need to write an app server to do your queries against the Drupal content store and return results, and connect your Android app to that
8:20 PM
Mark M.
actually, the "app server" may just be some custom PHP pages
but, again, I'm no Drupal expert
David: I'll swing back to you in a bit if you want to follow-up on this
Evan: got another question?
Evan
yes!
is there a way to wholly not support the landscape orientation and only have "portrait" mode for certain activities?
Mark M.
sure
Step #1: add android:orientation="portrait" to the <activity> element in the manifest
Step #2: probably also add android:configChanges="keyboardHidden|orientation", to prevent Android from destroying and recreating the activity for the non-existent orientation change
that's pretty much it
See the RotationFour example in The Busy Coder's Guide to Android Development
8:25 PM
Evan
and still have it enabled for other activities? (so certain activities are really only portrait- or landscape- specific)?
Mark M.
BTW, you'll need to repeat those two steps for each affected activity
yes, just apply the steps to the activities you want wired to portrait
the others will re-orient as normal
Evan
ah okay, so you define it per-activity...
thanks!
Mark M.
Chris: got another question?
Chris
OK, my next question is also with Patchy. When we make a new service connection we send a IPostListener object (listener) to the PostMonitor service in "service.registerAccount(prefs.getString("user", null), prefs.getString("password", null), listener);". Then in PostMonitor this callback gets assigned to a data member in an Account object. Then we call this callback and it operates on stuff back in Patchy. So my question is, when we call this callback from PostMonitor does the callback have the "context" of which it was defined inside of Patchy and that's why it can access stuff that was defined in Patchy? Man, I think I described that horribly, but maybe you get my point.
Mark M.
wow, you type quick
:-)
Chris
haha
Mark M.
the callback is an inner class of Patchy
hence, when we call a method on the callback object, it has an implicit reference to the outer class (Patchy activity) and can call methods on it
Chris
OK, that's what I was thinking. Another easy one for you.
Mark M.
that's OK -- I'm delivering training this week, so my brain is tired
Mike: got another question?
Mike R.
yeah. i've got several stack traces that point to onActivityResult. Can't figure out
here's a typical one
View paste (8 more lines)
java.lang.RuntimeException: Unable to resume activity {com.medpagetoday.medpage/com.medpagetoday.medpage.ArticlesList}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2506, result=0, data=null} to activity {com.medpagetoday.medpage/com.medpagetoday.medpage.ArticlesList}: java.lang.NullPointerException
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3128)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3143)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2684)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.Runtim
...
8:30 PM
Mark M.
OK, what does ArticlesList.java line 131 look like?
Mike R.
Let me get it out of svn
View paste
	@Override
		public void onActivityResult (int requestCode, int resultCode, Intent data) {
			switch (requestCode) {
			case MyNews.ARTICLE_ACTIVITY:
				myAdapter.notifyDataSetChanged();
				break;
			case MyNews.EDIT_LIST_ACTIVITY:
				buildArticleArray();
				if (articles.size() == 0) {
					appService.getConfig().getSubscriptions().remove(currentChannel.getChannelID());
					finish();
				}
				prepareActivityDisplay();
			}
		}
line 131 is myAdapter.notifyDataSetChanged();
Mark M.
well, myAdapter must be null
are you explicitly setting it to null anywhere?
Mike R.
no
Mark M.
OK
my best off-the-cuff guess, then, is that it is tied to a configuration change, such as a rotation
I haven't played with startActivityForResult() and orientation changes
Mike R.
i'll look there
Mark M.
if onActivityResult() is invoked after the destroy-and-recreate cycle, that might explain the null adapter
you might need to pass the adapter via onRetainNonConfigurationInstance(), which worries me some if you're using the holder pattern
oh, no, nevermind -- holder pattern will be OK
Mike R.
should have been re-created in the recreate cycle
8:35 PM
Mark M.
:: shrug ::
there's no question myAdapter is null, if that's the line that's getting the NullPointerException
I don't have a good way of diagnosing how it could be null, short of random guesses like the rotation one above
Mike R.
i'll try passing it via onRetainNonConfigurationInstance()
Mark M.
I'll try to make a point of testing out onActivityResult() and stuff like orientation changes in the not-too-distant future
Evan
i have another Q when it's my turn...
Mike R.
i'm through
Mark M.
OK
David: got another question, or a follow-up on your first one?
OK...Evan: got another question?
Evan
has anyone been successful in setting up Android source code in Eclipse so that you can just browse right to the appropriate framework class while navigating around your own project's source, and do things like set breakpoints in Android source code? I think if I can just get this set up so that my debugger will open android sources, i can get my focus issues figured-out
Mark M.
that is possible, but only if you are running your own custom-compiled firmware
otherwise, the source might not line up, for example
8:40 PM
Evan
i've downloaded the source for the version I'm debugging against... and I've got it set up as a project in eclipse...
but I'm having trouble figuring out how to get it to treat it as if it were a symbolic representation of the code, you know?
Mark M.
even though that is for platform development, that's probably the path you have to run down
Evan
YES!! THat's what I've been looking for!
thanks, Mark!
Mark M.
get the firmware compiled and running in an emulator, then follow those instructions
OK...Chris: got another question?
Chris
Evan reminded me of something. In Perl I remember I was able to step through my code and set breakpoints. Is there any way I can do that with Eclipse?
Mark M.
sure
Chris
I'd like to be able to get to a point and check out the values of variables and such.
Mark M.
AFAIK, it's the same as normal Eclipse development
which, since I don't use Eclipse, I don't know much about
Chris
OK, that's fine.
Evan
yup... check out the Debug perspective...
Mark M.
but Run > Debug should be your starting point
Chris
I'll read up on it.
Evan
if you've got your JDK and everything set up properly, it will just work
and you can set breakpoints and live-interpret expressions, and so on
very useful
Chris
Sounds like I'll need to dig into it. I've never used an IDE before.
8:45 PM
Chris
That was my question.
Mark M.
OK
Mike: did you come up with any other questions?
David: you out there?
OK, anyone got another question?
Chris
I have two more queued up when you're ready.
Mark M.
fire away
Chris
Last week I was going to come here and ask a question about how to keep my service from falling asleep. Then I found AlarmManager and your WakefulIntenService, which works great btw, in the tutorials book. I don't understand how the phone can go to sleep and not handle my service, but it can respond to stuff like AlarmManager. Do you have any more info on this or point me to the documentation that describes it?
Mark M.
Simple: AlarmManager relies on some other chip
the main CPU is off
Chris
Cool...
OK, last one...
Mark M.
however, the "wake up the CPU at such-and-so time" logic is being handled by some other chip
Chris
This is a pretty general question and I'm not sure what kind of answer I'm expecting, but a general one will probably be fine. I only have experience writing simple non-OO Perl scripts so jumping to Java, Android, an IDE is a lot to take in. I think the biggest obstacle has been trying to get familiar with the Android API. It's huge. You have any tips on how to get familiar with it? Right now, I'm just trying to take what I can from your books and make simple little apps. I think it's working out OK so far, but would like to hear any suggestions even if it is to just jump in and code.
Evan
has left the room
Mark M.
well, honestly, if you can spare the time, I'd recommend a few weeks puttering in Java *outside* of Android
8:50 PM
Mark M.
that can give you better Java and Eclipse experience, because it will line up with more available resources (e.g., blogs, online tutorials)
Chris
OK, I got some books. Just need to find some time to work on it.
Mark M.
that's a blog post where I list the parts of Java you need for Android
other stuff (e.g., Swing, servlets) aren't really used by Android
Chris
OK, I'm done. I just want to say that I purchased almost all the Android books and yours is far and away the best. I once purchased a newly released book at the store and started to work on some contacts stuff and Eclipse was telling me that it was all deprecated already :| So I downloaded the latest version of your books and everything was updated and worked!
All right. I'll check it out. Thanks a lot!
Mark M.
glad my stuff helps!
anyone else have a question?
8:55 PM
Mark M.
OK, well, we'll wrap the chat for today, then
next one is Thursday, same Bat time, same Bat channel
have a pleasant evening, everyone!
Chris
has left the room
Mike R.
has left the room
David
has left the room
Mark M.
turned off guest access

Friday, September 17

 

Office Hours

People in this transcript

  • Chris
  • David
  • Evan
  • Mark Murphy
  • Mike Renda