===[ More Android Morsels| January 11th, 2009 ]
Finishing off my port now! Once it’s done I’ll do the whole “Android vs. iPhone” breakdown, but for now here’s just a few more gotchyas you may hit:
- If you want to start an activity, remember that you have to add it to your app’s XML manifest file. Don’t worry, it only takes you a few iterations on “run, get exception, wonder why, remember” until you mind remembers to do this. It’s be great if some Java guy could integrate this into Eclipse so that when you created a new class you could have it automatically insert it.
- URIs are not strings. To get from a URI to a string, use toString(). To go the other way, use parse().
- Want to pop up a message box? In Android the class you need is AlertDialog. Here’s some sweet sample code:
new AlertDialog.Builder(this).setTitle("Title"). setMessage("Yo").setPositiveButton("OK", new DialogInterface.OnClickListener() { /* whatever */ } ).show();I found that code on the anddev forums. Message boxes were tricky to figure out because there used to be a different way to show them that was removed as the SDK matured. Also check out how the click listener method is specified via anonymous delegate.