Android Notebook, page 3

Perhaps just because it’s an initial tutorial, but the event handling model feels like a sort of monolithic Java 1.0/Mac OS 6 event loop rather than the more flexible event listener based approaches of Swing and other more modern GUI frameworks.

Local variable access is much more efficient than field access in the VM. I guess the CPU (or battery) is too underpowered to do fancy JIT tricks, as I’d expect a good optimizer to account for this. Worth remembering. Hmm, does Dalvik even have a just-in-time compiler? Apparently not.

An Intent holds a map of user defined properties wrapped up as a Bundle named extras. Hmm, what is an intent or an activity anyway? Backtracking a bit, “An activity is usually a single screen in your application. Each activity is implemented as a single class that extends the Activity base class….Android uses a special class called an Intent to move from screen to screen. An intent describes what an application wants done. The two most important parts of the intent data structure are the action and the data to act upon. Typical values for action are MAIN (the front door of the application), VIEW, PICK, EDIT, etc. The data is expressed as a URI. For example, to view contact information for a person, you would create an intent with the VIEW action and the data set to a URI representing that person.”

On the other hand, I’m not sure why intents/activities should be wired up in XML in AndroidManifest.xml. This feels more like a job for Java. Maybe it’s just that I think of XML as the right place for nouns and adjectives, but I get nervous when we start turning it into verbs. (Just like I get nervous when we start using code to describe things rather than behavior.) I am not sure this is actually sensible. It may be perfectly reaosnable to use XML to describe behavior and procedural code to describe data. However, I think there’s the beginnings of another general principle here:

Use XML to describe things. Use code to define processes.

How functional programming languages fit into this I have no idea. (And as I said, this may not actually be a good principle anyway.)

Leave a Reply