commonsguy/cwac-locpoll — pull request #3 by alexbirkett (2011-12-18 12:20:45+00:00)
Title: Another attempt.

Once again I´m surprised by Android. This seems like a massive bug in fundamental functionality. It´s a pretty crappy marshaling system if it can´t marshal and unmarshal data!

So it seems to me that the only choices are:

1. add every parameter to the bundle individually. This is the status quo. IMHO there are several drawbacks to this. Each key is long and bloats the app. It becomes error prone as more parameters are added. The code to get and set the keys is not as readable as simple method calls. The keys for input and output are all jumbled up.

2. Internalize and Externalize an object to a byte array and send the byte array via the intent.

I´ve gone for 2. It may look a bit like over engineering given that I´ve only added two extra parameters but I plan to add more. I want to add some heuristics to give up using the GPS quicker if it´s obvious from the satellite signal strengths that it´s not going to get a lock.

Do you think it´s a good idea to throw a RuntimeException in the case below? If an IOException is thrown by the ByteArrayOutputStream then it´s pretty much game over for the app.

```java
/**
* Externalize object that implements SimpleSerializable
* @param objectToExternalize object to externalize
* @return byte array representing object
*/
public static byte[] externalize(SimpleSerializable objectToExternalize) {

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(
byteArrayOutputStream);
try {
objectToExternalize.writeToStream(dataOutputStream);
} catch (IOException e) {
// IOException should only occur in an OOM situation since we´re
// writing to memory. App should not proceed.
throw new RuntimeException(e);
}

return byteArrayOutputStream.toByteArray();

}
```