Posts tagged android

Android For Dummies & TekPub

My last post announced that I was writing a book … so …

What does this mean for the Introduction to Android TekPub.com series?

Great things actually – if you prefer to learn via reading, you can do that with the book. If you prefer to learn via video, you can do that with Tekpub.com, all via the same author. The book and the TekPub series cover different example applications so you’d get the most out of it by learning from both (in my opinion). Regardless, this will only enhance the learning for you by having two options – a book, or a video series.

More episodes of the TekPub series are coming soon.

Android Development For Dummies

I can finally announce it, I’m writing the first official Android Application Development for Dummies book.

I’ve been writing for awhile now and had a lot of inquiries into what I’ve been writing about. I’m glad to finally be able to say what I’m working on.

The book is slated to be released this fall.

Pre-order now by clicking on the image on the left.

Android: ‘Must Override a Superclass Method’ Errors

I’ve been working by myself on all of my Android projects and just recently I need ed to expand my workforce to beyond that just myself. Therefore I needed to make my first hire for my company Agilevent. In doing so I needed to get my code over to another developers machine and I ran into all kinds of problems.

Background

The code is stored on GitHub in a private repository and the new developer had access. They had recently set up Eclipse and the ADT with Java 1.6. Everything was working golden. We could create a new project and everything worked fine. Except … when we tried to import the recently cloned GitHub project.

After importing Eclipse would report “Must Override a Superslass Method” on all kinds of methods all over the place (literally 86 different places in this one app).

Resolution

After a ton of futzing around we found the problem. Eclipse was defaulting to Java 1.5 for the imported project. I’m learning more and more and more about Java and its idiosyncrasies every day. In Java 1.5 classes can only be decorated with @Override when overriding a superclass method. In Java 1.6 if you have classes implementing interface methods you can decorate them with @Override and everything’s golden. You cant do that in 1.5. AKA: The source of the errors.

So where to change it?

Choose Window –> Preferences –> Java –> Compiler and ensure 1.6 is selected in the Compiler Compliance Level. If that is set and you still have problems, then in the same window, choose “Configure Project Specific Settings …”, choose the project in the chooser, and enable the project specific settings checkbox and select 1.6 in the Compiler Compliance level.

Fun times. Now if I could only get those two hours back …

Gotchas with Rooting a MyTouch Slide

I got a hold of an extra MyTouch slide for testing and wanted to root it in order to put some a different ROM on there (namely Cyanogen). The MyTouch slide root instructions are fairly well documented and have worked for a lot of people. Unfortunately they did not work for me and I got stuck where 90% of most people get stuck, in the “loop”. I was stuck in this mode for a week and nearly called it quits until I found this Gem last night. I could not get the loop to recognize my device as “offline”. Well, it would, but only for a split second.

I then found out why:

The instructions don’t point this out, and maybe this case is only due to my device but here goes:

  • With the USB unplugged from the Phone and computer, Boot into HBOOT (with the phone off, press Power + the Down Volume). Then wait a second for the boot loader to try to find some images and then once its done navigate down to “recovery” (DO NOT GO INTO RECOVERY YET), so at this point “recovery” is just highlighted. Plug the USB into the phone, the other end of the USB should NOT be plugged into anything. So now you should have a phone with a USB cord connected/dangling not connected to the computer. Read this through, then do it: Now you will need to start the loop. Then as soon as you can, plug the USB into the computer. As soon (I mean lightning quick here people) as you feel the USB pop into place ENTER RECOVERY MODE (hit the power button). This has to be done before your phone recognizes that its plugged into the USB. As soon as the phone recognizes its in USB mode it will change from HBOOT to HBOOT with USB (or something like that, you’ll see it at the top of the screen in blue when in HBOOT). Notice: the switch from HBOOT to HBOOT WITH USB is almost instantaneous. Its about 1/2 of 1 second, its that quick. So AS SOON AS YOU feel the USB click (gotta be super fast people), enter recovery mode.
  • I had to use the stock SD card that came with the phone, not a new/replacement one. Previously I had a 4 gig card in there from an old phone which was actually bought at Micro Center (had photos/files/etc on it). I read somewhere that you needed to use a stock SD card (I guess the types are different). Long story short: The new card I had in the phone did not allow it to show up as “offline”. I used the stock SD card and magically the phone started showing up in the loop immediately.

That pretty much did it for me. I was able to root the phone, install other roms and then I went full circle and brought it back to factory settings with this ClockworkMod nandroid backup.

So key points: Be fast with plugging in the USB and entering recovery mode. Use the stock SD card not some junk you bought from Micro Center (like me). :)

Android: Db4o StackOverflowError

I‘m using db4o for a persistence store in an Android app since db4o allows FREE usage in Android apps I decide it would be a good fit. Until I ran into the an error I could not get around for a couple of weeks.

Over the last couple of weeks I’ve been dealing with an error from hell, the StackOverflowError. I reworked the object model, I cut down the calls, trimmed up all the fat in the Android app I could find and I couldn’t find what was causing the db40 classes to throw a StackOverflow error.

The error that I’d get back would look like this:


06-12 18:31:06.630: DEBUG/dalvikvm(17018): newInstance failed: no ()
 06-12 18:31:06.640: INFO/dalvikvm(17018): Stack overflow, expanding  (0x41869200 to 0x41869000)
 06-12 18:31:06.640: INFO/dalvikvm(17018): Shrank stack (to 0x41869200,  curFrame is 0x41869698)
 06-12 18:31:06.640: DEBUG/AndroidRuntime(17018): Shutting down VM
 06-12 18:31:06.640: WARN/dalvikvm(17018): threadid=3: thread exiting  with uncaught exception (group=0x4001b180)
 06-12 18:31:06.690: DEBUG/dalvikvm(17018): GC freed 5995 objects /  562312 bytes in 36ms
 06-12 18:31:06.800: DEBUG/dalvikvm(17018): GC freed 3836 objects /  436456 bytes in 79ms
 06-12 18:31:06.840: DEBUG/dalvikvm(17018): GC freed 687 objects / 167288  bytes in 33ms
 06-12 18:31:06.860: ERROR/AndroidRuntime(17018): Uncaught handler:  thread main exiting due to uncaught exception
 06-12 18:31:07.020: DEBUG/Gmail(140): MailEngine.sendOrSaveMessage  messageId=1338387167469109248 refMessageId=0,  conversationId=1338387167469109248
 06-12 18:31:07.030: WARN/ActivityManager(76): Activity pause timeout for  HistoryRecord{449684b8 com.google.android.gm/.ComposeActivity}
 06-12 18:31:07.090: DEBUG/dalvikvm(17018): GC freed 3055 objects /  566504 bytes in 215ms
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):  java.lang.StackOverflowError
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.foundation.CircularLongBuffer4.remove(CircularLongBuffer4.java:73)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.caching.LRU2QLongCache.produce(LRU2QLongCache.java:40)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.caching.LRU2QLongCache.produce(LRU2QLongCache.java:14)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.io.CachingBin.getPage(CachingBin.java:153)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.io.CachingBin.readInternal(CachingBin.java:65)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.io.CachingBin.read(CachingBin.java:57)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.io.BinDecorator.read(BinDecorator.java:40)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.io.BlockAwareBin.blockRead(BlockAwareBin.java:90)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.IoAdaptedObjectContainer.readBytes(IoAdaptedObjectContainer.java:210)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.IoAdaptedObjectContainer.readBytes(IoAdaptedObjectContainer.java:201)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.LocalTransaction.readPointer(LocalTransaction.java:387)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.LocalTransaction.getCurrentSlotOfID(LocalTransaction.java:355)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.LocalObjectContainer.readReaderOrWriterByID(LocalObjectContainer.java:437)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.LocalObjectContainer.readReaderByID(LocalObjectContainer.java:415)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.LocalObjectContainer.readReaderByID(LocalObjectContainer.java:419)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.marshall.UnmarshallingContext.readBuffer(UnmarshallingContext.java:127)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.marshall.UnmarshallingContext.read(UnmarshallingContext.java:40)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.ObjectReference.read(ObjectReference.java:304)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.ObjectReference.read(ObjectReference.java:290)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.ObjectContainerBase.getHardObjectReferenceById(ObjectContainerBase.java:956)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.marshall.AbstractReadContext.classMetadataForObjectId(AbstractReadContext.java:85)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.marshall.AbstractReadContext.readObject(AbstractReadContext.java:57)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.marshall.AbstractReadContext.readAtCurrentSeekPosition(AbstractReadContext.java:46)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.OpenTypeHandler.read(OpenTypeHandler.java:172)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.Handlers4.readValueType(Handlers4.java:313)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.marshall.AbstractReadContext.readAtCurrentSeekPosition(AbstractReadContext.java:48)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.marshall.AbstractReadContext$1.run(AbstractReadContext.java:38)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.marshall.SlotFormat.doWithSlotIndirection(SlotFormat.java:64)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.marshall.AbstractReadContext.readObject(AbstractReadContext.java:36)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.handlers.array.ArrayHandler.readInto(ArrayHandler.java:381)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.handlers.array.ArrayHandler.readElements(ArrayHandler.java:363)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.handlers.array.ArrayHandler.read(ArrayHandler.java:355)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.Handlers4.readValueType(Handlers4.java:313)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.marshall.AbstractReadContext.readAtCurrentSeekPosition(AbstractReadContext.java:48)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.OpenTypeHandler.read(OpenTypeHandler.java:172)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.Handlers4.readValueType(Handlers4.java:313)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.marshall.AbstractReadContext.readAtCurrentSeekPosition(AbstractReadContext.java:48)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.marshall.AbstractReadContext$1.run(AbstractReadContext.java:38)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.marshall.SlotFormat.doWithSlotIndirection(SlotFormat.java:64)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.marshall.AbstractReadContext.readObject(AbstractReadContext.java:36)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.marshall.AbstractReadContext.read(AbstractReadContext.java:28)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.FieldMetadata.read(FieldMetadata.java:811)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.FieldMetadata.activate(FieldMetadata.java:646)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.handlers.StandardReferenceTypeHandler$2.processAspect(StandardReferenceTypeHandler.java:93)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.metadata.MarshallingInfoTraverseAspectCommand.processAspect(MarshallingInfoTraverseAspectCommand.java:52)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.metadata.StandardAspectTraversalStrategy.traverseAllAspects(StandardAspectTraversalStrategy.java:24)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.ClassMetadata.traverseAllAspects(ClassMetadata.java:2086)
 06-12 18:31:07.100: ERROR/AndroidRuntime(17018):     at  com.db4o.internal.handlers.StandardReferenceTypeHandler.traverseAllAspects(St

After posting on the forums I was given some advice from Fabio (who looks to be an employee),. He advised to try the TransparentActivation mechanism. I implemented it on my 6 classes and in the configuration of db4o as shown in an example in the previous link.

Magically, the error went away. So, if you get this error, implement the Activatable interface (or IActivatable in .NET).

NOTE: This could be vastly useful when Windows Phone 7 is released if you’re using it for .NET.