Office Hours — Today, November 17

Tuesday, November 10

Nov 17
7:45 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Nov 17
7:55 PM
ostaski
has entered the room
ostaski
Hey Mark
Nov 17
8:00 PM
Mark M.
howdy!
ostaski
I'm back for more ... same ol' thing. :)
Mark M.
at least you're persistent
ostaski
Bashing your head against the wall is fun ... when it's over
ostaski
Here's a link to my question posed at stackoverflow: http://stackoverflow.com/questions/1745688…
Mark M.
Yeah, I saw it
ostaski
I've got the full Photographer activity there along with an expanded version of the calling class from last week.
ostaski
Googling "App freeze timeout expired" returns a few posts suggesting onCreate() or onResume() are taking too long.
Mark M.
Well, you're starting the Photographer activity off a background thread, which is a trifle unusual.
Mark M.
Do you have a compiled APK that demonstrates the problem?
ostaski
Yes.
Nov 17
8:05 PM
ostaski
Do you want me to upload that?
Mark M.
Yes, if you don't mind -- I'll try it on some other equipment.
Mark M.
Just to rule out it being something funky with your G1
Mark M.
BTW, is your G1 running 1.6?
ostaski
ostaski
Yes, my G1 is running 1.6
Mark M.
OK, it's installed -- now what do I do to trigger the problem?
ostaski
I'd hit the menu, select alarm delay (I think) and change it to 15 seconds.
ostaski
then hit menu again and hit Arm
Nov 17
8:10 PM
Mark M.
OK, it crashes on me too
Mark M.
though the preview then appears
ostaski
yes, I get the preview too
ostaski
shouldn't the emulator, well emulate?
ostaski
works fine on the emulator
Mark M.
The closer you get to hardware, the more fakey the emulator gets
Mark M.
If you notice, your error has Qualcomm stuff yelping, and the emulator definitely won't emulate that
ostaski
another one for Yogi Berra
Mark M.
After all, not all devices will have Qualcomm chipsets
ostaski
makes sense
ostaski
Seems like the Photographer's onCreate is setting this off
ostaski
any way to move some of that elsewhere?
Mark M.
Hang on
Mark M.
I'm trying to get my own Camera/Preview project on here
ostaski
K
Mark M.
OK, that code definitely works.
Mark M.
Next, let me make a visual comparison of code -- give me another minute
Nov 17
8:15 PM
Mark M.
Anything unusual about your res/layout/photographer.xml file? Is it just a full-screen SurfaceView?
ostaski
just this
ostaski
View paste
<?xml version="1.0" encoding="UTF-8"?>
<android.view.SurfaceView xmlns:android="http://schemas.android.com/apk/res/android"
		android:id="@+id/preview"
		android:layout_width="fill_parent"
		android:layout_height="fill_parent"
		>
</android.view.SurfaceView>
Mark M.
Yup, that's pretty boring.
Mark M.
OK, the only two differences I see between your code and mine are not in Photographer, per se.
ostaski
except for the anr :)
Mark M.
1. Your activity is being launched by another activity, rather than being the first activity.
Mark M.
(actually, to be more accurate, I don't know that you're launching this from an activity vs. a service)
ostaski
activity
Mark M.
2. Your launching code is calling startActivityForResult() on a background thread.
ostaski
right
Mark M.
Of those, #2 scares me more
ostaski
here's the flow:
ostaski
1) hitting the arm sets off a counter
ostaski
2) once the counter is through, the Photographer takes over
Nov 17
8:20 PM
ostaski
3) once the photo is taken (and there is an old photo), the comparator takes over
Mark M.
Can you use View#post() or runOnUiThread() or something to call startActivityForResult() on the UI thread?
ostaski
not sure I follow
ostaski
you may recall this is an unattended app ... no user interaction
Mark M.
So?
Mark M.
The arm menu is in an activity
Mark M.
That activity has a UI thread
Prasanna P.
has entered the room
Mark M.
Use View#post() or Handler#post() or Activity#runOnUiThread() or something to get your startActivityForResult() to be called on the UI thread
Mark M.
Hello, Prasanna!
ostaski
that's the wiia activity ... where the background thread resides
Prasanna P.
Hello Mark!
Mark M.
ostaski: I understand that
ostaski
K
Mark M.
However, it may not be safe to call startActivityForResult() from a background thread.
Mark M.
So, your background thread needs to tell the UI thread to call startActivityForResult().
Mark M.
If this were AsyncTask, you'd do it in onPostExecute().
Mark M.
Since this is a manually-constructed thread, you have to use lower-level techniques.
ostaski
OK, I'll give that a shot.
Mark M.
Prasanna Perera: got any Android development questions?
Nov 17
8:25 PM
Prasanna P.
I was reading that developers are finding it hard to write apps that work with all the different hardware, firm ware, and android OSs. What is your take on this? What are ways that we can write code that works on as many devices as possible?
Mark M.
Grab Version 2.8 of _The Busy Coder's Guide to Android Development_, if you haven't downloaded the update already. I have new material covering just that sort of topic.
Mark M.
And, it's an area that will get continuing coverage over the next several months.
Prasanna P.
OK
Mark M.
Upshot: there is some tedium, and things will be much better once Android 1.5 has vanished, but it's not horrible for most apps
ostaski
"reflection plus a wee bit of caching"
Mark M.
Yup, letting a bit of my Celtic ancestry leak through, there. ;-)
ostaski
despite my name, I'm half Irish
Mark M.
Right now, it feels like the Contacts API changes in Android 2.0 are one of the big pain points, which is why I have a hunk of time tomorrow set aside to work on that.
Mark M.
ostaski: actually, I'm only a quarter Irish, but I find Irish ancestry to be more entertaining than German ;-)
Prasanna P.
I have lot of Java experience but new to Android development. I want to get up to speed as soon as possible to develop a basic app. Any suggestions?
Mark M.
You mean, besides reading the books you subscribed to? :-D
Mark M.
The _Tutorials_ are the quickest path to having a running app.
Prasanna P.
Yes.
Prasanna P.
OK. Thanks.
Nov 17
8:30 PM
Mark M.
Note that the _Tutorials_ are slightly out of date, in that they do not take into account Android 1.6/2.0
Prasanna P.
You mean the tutorials you provide right.
Mark M.
I have an update scheduled soonish
Mark M.
Yes, sorry.
Prasanna P.
Great.
Mark M.
By _Tutorials_, I mean _Android Programming Tutorials_, one of the three books in your Warescription.
Mark M.
(note to self: choose shorter book titles)
Prasanna P.
Yes. Got it :)
Mark M.
Beyond that, pick an itch and scratch it -- by which, I mean that you will probably move faster on an app that you actually care about, rather than some throwaway "Hello, world" sort of app
Prasanna P.
This may be a basic question ... I want to have a menu on my opening screen. Should I use a the ListView or a bunch of separate Buttons? Does this make sense.
Mark M.
Either works
Prasanna P.
So how do you decide?
Mark M.
Buttons are a bit easier
Prasanna P.
OK
Mark M.
Personally, I don't put menus on my opening screens. ;-)
Prasanna P.
Why not? :)
Mark M.
Most apps are probably better served sending the user into the most-frequently-used activity, then letting them navigate from there.
Mark M.
In that case, X% of the time, the user is in the right spot immediately.
Mark M.
With a menu activity, 0% of the time the user is in the right spot immediately.
Prasanna P.
Got it ...
ostaski
also there's a menu button, right?
Nov 17
8:35 PM
Mark M.
Certainly. An option menu is the standard Android approach for that sort of thing.
Mark M.
Now, the one place where having an up-front menu of buttons may make sense is in a game.
Mark M.
Games using the 2D canvas or OpenGL may have a more difficult time offering navigation off of those screens.
Mark M.
Or, the game may not make sense until you chose a level or map or something.
ostaski
Another question ... what would be the best approach to password-protecting and app. Say, if a user enters a password in their preferences, the application will run and any more user interaction would pop up a window requesting the password. Then, if the password is correct, the next action would be revealed, but if the password is incorrect, the app would ignore the user?
Mark M.
Most of those cases, people tend to use Button, or more commonly, ImageButton.
Mark M.
ostaski: The app could ignore the user, or finish() and push the user back to the home screen.
Mark M.
The tricky part there is preventing other apps from launching Intents to bypass your password.
ostaski
how to implement this ... do you know of any examples?
Mark M.
Off the cuff, I can't think of any, though I would assume OI Password Safe and other password managers probably do it.
Mark M.
I think OI Password Safe is open source.
ostaski
OK, I'll see if they have a blog about how they did it.
Prasanna P.
In addition to your code tutorials what are other good code examples?
Mark M.
Well, there's the API demos that come with the SDK.
Nov 17
8:40 PM
Mark M.
You can also look at the Android source code itself, if there's something specific you want to see how it is used.
Mark M.
Use Google Code Search (http://www.google.com/codesearch) and add package:android to your search query
Mark M.
That'll restrict your search to Android-related projects.
Mark M.
I use it all the time.
Mark M.
Though a bit less right now, until I get a sense that the Eclair (2.0) code is what's indexed.
Mark M.
After that, I'd subscribe to the Planet Android aggregated feed and watch for development-related posts.
Prasanna P.
What do you mean by 'Though a bit less right now, until I get a sense that the Eclair (2.0) code is what's indexed.'
Mark M.
Google Code Search indexes the git repositories that contain the Android open source code.
Mark M.
Git, like any version control system, uses branches.
Mark M.
And, a lot of the code gets developed internal to Google and gets dumped out into the public git repos sporadically.
Mark M.
So, for a while, 2.0 was on the market but the source code was still 1.6.
Nov 17
8:45 PM
Mark M.
Only recently has JBQ merged the Eclair code in, and I'm not sure if it's on the branch that Google Code Search indexes.
Mark M.
Haven't tried it in the past few days.
ostaski
Have to run, Mark ... be back next week, no doubt. :)
Mark M.
ostaski: OK, have a pleasant evening!
ostaski
Thanks for the insights, as always.
Prasanna P.
Mark I am going to head out. Thanks much for your time. I will be back at future office hours.
ostaski
U2
ostaski
has left the room
Prasanna P.
has left the room
Mark M.
@Prasanna: OK, see you later!
Nov 17
8:55 PM
Mark M.
turned off guest access

Tuesday, November 10

 

Office Hours

People in this transcript

  • Mark Murphy
  • ostaski
  • Prasanna Perera

Files in this transcript

Adblock