Sunday, October 31, 2010

titbits left out from the Android documentation

Excellent explanation by Dick Wall (from thread http://groups.google.com/group/android-beginners/browse_thread/thread/31e6ecd386b29cbe/2901a6a6793de6f5):

1) vnd.android.cursor.item/vnd.google.note...

This is a MIME type - MIME stands for Multimedia Internet Mail Extensions
and was created for email attachments to tell the receiving computer what
type of file was attached and give it a clue on how to deal with it. It has
since been adopted as a pretty well used standard for general typing of
files, e.g. it is common to see something like "audio/mp3" to indicate an
audio mp3 file.

There are generally two parts - a category (before the / ) and a specific
type (after the / ).

In this case, our category is an android cursor item - because this is
pretty specific, the vnd indicates that this is a "vendor" definition - i.e.
we defined it, and quite possibly other people don't agree with our
unilateral definition (although the IANA will register such things if asked
which makes it official - sort of...)

The vnd.google.note means that this is a note type, for Google, and again
vendor defined

So, if your organization was hepcats.org and your item was a superthingy,
you might use:

vnd.android.cursor.item/vnd.hepcats.superthingy (the category is still an
android cursor item assuming you want to return it through a cursor...)

For more info on MIME, I can suggest the following links:

http://en.wikipedia.org/wiki/MIME
http://www.mhonarc.org/~ehood/MIME/ (this one is a bit heavy, but contains
the actual RFCs that define the standards if you really want to know what
makes it tick - you don't need to read all this to get along with MIME types
though)

2) In the line "
android:value="com.google.android.notepad.action.EDIT_TITLE" />"...

The "com.google.android.notepad.action.EDIT_TITLE" is just a string that
your manifest and your Java source code constants can agree on, that said
there is a convention in use here that should probably be adhered to in
order to avoid trouble.

In Java source code, source is organized into packages that look like:

com.google.android.mysubpackage...

or

org.flyaway.myapp.mylibrary

The first two parts of the package usually correspond to an internet domain
name that the author owns or is associated with, so for example, Google owns
google.com, so many of our packages start with com.google (note the reversal
- packages in Java source get more specific as they progress, so com being
the most general term is used first).

Going with the hepcats.org example, if you own that you could use

org.hepcats.myapp.mysubpackage

to put your source code in.

The actions follow this same convention, but tend to put an extra .action.
before the actual action name you want to use, so:

org.hepcats.bonanzanotes.action.EDIT_MY_STUFF might be something you used.
Alternatively it is not wrong to put android in there after hepcats as well
as a further categorization of what you are writing (as in "this is my
android code"), so you might use
org.hepcats.android.bonanzanotes.action.EDIT_MY_STUFF instead.

3) In the following lines, what do 'DEFAULT', 'ALTERNATIVE', and
'SELECTED_ALTERNATIVE' mean?

These are convenience definitions provided for you by Android itself.
DEFAULT means that this action can be considered a default action for the
type of data specified - i.e. something requesting the default action for a
particular data item can get sent straight to this intent. It's like saying
"I know this one, let me handle it"

ALTERNATIVE means that this can act as one of the alternatives that the user
can select to handle a particular request or item. If there are several
alternatives, the user will (or may) be prompted as to which one to use.

SELECTED_ALTERNATIVE means that the action applies to something the user
currently has selected.

You can read a lot more about all this in the Intent class reference:

http://code.google.com/android/reference/android/content/Intent.html

There is plenty of meaty documentation on this, and it should fill in any
gaps in my explanation.

Friday, July 9, 2010

Using gmail or Android marketplace without Data plan (T-mobile)

Just wanted to post this in case someone else finds it useful. Unfortunately, T-mobile reps incorrectly insist you cannot open the Android Marketplace without a data plan. Searching on the topic brings up lots of uncertain older posts

I bought a new HTC MyTouch Slide off ebay. I already have a Tmobile account but did not want the data plan. I connected to my home WIFI and was able to browse the internet. However when trying to go to
Android marketplace or login to gmail, it waits, "Signing in, need to connect with Google servers..." and then after 2 minutes says, "You dont have a network connection. .. your phone may not be provisioned
for data services. Please try again when connected to a mobile network, or connect to a WIFI network."

The solution was to go to Home, Menu, Settings and then disable the "Enable Always On Mobile Data".
Under Settings, 'Wireless and Networks' scroll to the bottom, 'Mobile Network settings' and uncheck "Enable Always On Mobile Data".

And it worked!

Thursday, July 1, 2010

How to duplicate a row of a database table, with foreign key dependencies

I was required to duplicate a row of a database table, with foreign key dependencies. It is not a trivial problem as the dependent rows of the foreign key tables have to be created, and then the values of these ids taken and the fields updated in the primary table. Of course, the dependent rows will likely also have foreign key fields so their dependent table rows have to be created first. This ripple effect can go on and on.

This is hard to do in sql and thinking about it, it would be easier to do using recursion in a programming language.

Steps:

write a recursive method
NewId createRow() {
  for each dependent foreign key field {
   newId = dependent table.createRow()
   update foreign key field with newId
  }
}

"for each dependent foreign key field": this list can be obtained using JDBC.

Wednesday, June 30, 2010

Using Model-View-Controller differently - to isolate volatile parts of your application

Even if your application does not have a GUI, you can benefit from MVC.
I was trying to write automated tests using JUnit/Cactus and it quickly got unmanageable.
Each test case involved creating several business objects, filling each with lots of data, and then invoking on business services. Since there were different combinations of the data, for each test case, one had to create a new class. Ridiculous!
The solution was:
View (interacting with the outside)
This was not a GUI, but simply a JUnit class.
TestCases contains the test methods, and inherits from JUnit’s TestCase. It has a reference to the concrete data set and instantiates the specific data set. TestDataSet0, TestDataSet1…
It invokes on TestDataSet0 to retrieve the BusinessObjects object to perform its testcases.

Model (Volatile part)
Interface TestDataSet has getter methods
BusinessObjects getBOCombination1()
BusinessObjects getBOCombination2()…
Concrete class TestDataSet0,1,2… implements this interface.
It has a reference to class BusinessObjects.
The data can be filled from the database, or simply hardcoded.

Controller
Class BusinessObjects contains methods to populate each Business Object.
populateBO1(), populateBO2()

So each time there is a different combination of data, create a class TestDataSet_N - yes, it is another class but all it is concerned with is the hardcoding of data, or retrieving of that data combination from the database.

The advantage of this design is, it allows reuse of methods, isolates the hard-coded data (that keeps changing from case to case) and enables more rapid progress.

Monday, June 21, 2010

What Next Android?

Just my 2 cents. Google will do its own thing regardless of all the
developers hanging from the Android train - our financial wellbeing is not its concern.

It seems to me that Google is yet to figure out, "What Next?".
Someone on the newsgroups said that Android and Chrome were built because Google didn't want to be shut out from the advertising platforms like Nokia, iPhone. I think they correctly saw it as a futuristic platform and wanted control of mobile platforms, just like M$ did on PCs. So they built this thing called Android and now that they control it, are not quite sure how to profit from it. It is just another mobile operating system with an app store, like Palm, iPhone, Nokia.

Can you write an app on Android that couldn't have been written on the
other OS'es? Does a user with an Android phone have a better day than
those with no-name phones? Good Advertising seduces us to perceive in
a new light what is 'cool' and that acquiring it will also make us
'cool'.