An iPhone Developer Learns Android- Some Thoughts



At first, doing a “Hello World” was quite easy, the hardest part was learning Eclipse (for Mac):
– Open Eclipse and don’t worry about opening a project, on the left hand side will be all of your “workspace” projects.
– Running (the play button) does an automatic build
– Mouseover red squiggly underlines to find build errors

I lost one of my panes, and that took forever to learn how to open again: I still can’t confidently tell you how (sorry).

Some basics to coding in Java/Android for Eclipse:
– To log, you have a few options: import “import.android.util.Log” and write the following:
Log.e(“onestring”,”anotherstring);
You can do Log.e (error- it’s red in Log pane), “d”, or “a” (assertion).

To add resources- media, data files, etc.- in iPhone you drag resources to your project in Xcode. For Eclipse, copy to the “/res/raw” directory, with no mention anywhere else. I assume this gets indexed on compile.

Layout is still a total drag. The general idea is you can programmatically create your layout or use an XML file, and update values from code. I have to create 25 objects, so it’s programmatic. Good news- compared to iPhone, there are a lot more settings and variances. Bad news- there are different… ways of building the objects so it’s ending up being far different than my iPhone version. Still mastering things like “centering a button,” and “saving state,” “animating a fade,” etc. May give up on some of those bells and whistles for the first version.

Disappointed with file reading in Android- it’s quite easy in iphone, you can map a file directly to an NSDictionary object. I’ll include my code here for parsing a simple key,value data file.


final Hashtable wordsHT = LoadText(R.raw.dict1a);

public Hashtable LoadText(int resourceId) {
// The InputStream opens the resourceId and sends it to the buffer
InputStream is = this.getResources().openRawResource(resourceId);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String readLine = null;
Hashtable tmpHT = new Hashtable();

try {
// While the BufferedReader readLine is not null
while ((readLine = br.readLine()) != null) {
String[] wordA = readLine.split(":");
tmpHT.put(wordA[0], wordA[1]);
}

// Close the InputStream and BufferedReader
is.close();
br.close();

} catch (IOException e) {
e.printStackTrace();
}

return tmpHT;
}

Comments welcome of course.

,