Wednesday, May 11, 2011

The Android Market is FULL of Viruses!

I first heard those words from a gadget loving iPhone fan-boy whom also happens to be a very good friend of mine.  We don't often discuss the pluses or minuses of the 2 platforms because he's not a geek.  He is, by all accounts, in love with anything Apple is willing to put on the shelves for us to consume.

He does ask how my application development is going and is at least interested in that I'm interested.  He asked me one day about all the viruses in the Android App Store and when refuted by me had the evening news on his side.  He did concede that they weren't necessarily viruses in the traditional sense, but rather poorly written applications that cause performance problems, consume more data than they should, etc.  I exclaimed that if that were the classification for a virus then Apple's own machines are the preferred platform for the world's leading virus ... Photoshop.  :)

His comment and the opinion of the main stream media stuck with me.  I can't do anything about it, but it did get me wondering about the complete lack of an approval process for Android developers' submissions.  Apple has one.  Windows Phone 7's is unbelievably thorough.  I have had 2nd hand experiences with both.  Android has none.  That helps keep a low cost to entry, but it does open the door for some poor code to end up on users' phones.

Thank goodness there are a few good developers out there writing quality code; like me!  But wait, I wrote a "virus."  It's true.  I downloaded the Android SDK, the Eclipse ADT plugin, Eclipse and even the Subclipse SVN plugin.  I have source repositories setup to store my code change by change and I maintain this blog to discuss the application, coding in general, etc.  I can Google anything and figure out how to make something work.  That doesn't mean that's how it should or needs to work.  Therein lies the problem.  I can write some fancy code, but you don't know what you don't know!

So, why was my app a virus?  Several versions ago I switched the UI to a tabbed view.  There was major refactoring involved in doing so.  Shortly thereafter I was experimenting with JSON string parsing and how that might benefit my app.  I was debugging something in the JSON app I was building and had left the DDMS perspective in Eclipse open while I was researching.  I kept noticing screen updates in my peripheral vision but it wasn't until I stopped what I was doing to investigate that I realized I had a coding mistake.  My other app had been opened to do some other work and it was the culprit.  It was requesting a new ad from AdMob even though the application was not in the foreground.  It should have been paused and had no activity going on.  In all the refactoring I had lost my onPause() method.  After getting that back into my code things were normal again.  Thank goodness it was for something as small as an ad!

That spurred me to start doing some reading on the Application Life Cycle.  There's fabulous documentation on it provided by Google.

So is the Android Market really full of viruses?  I can tell you that I've seen some really crappy code over the years.  I can also tell you that I take special care (certainly more than most!) to understand my code and do extensive testing.  There are no formal checks and balances and even with the best of intentions my code was consuming more data and thusly more battery power than it should have been.  Whether it's full of viruses or not I know that it has 1 less as of several weeks ago and I will be much more conscience of how my phone performs after I install something new.

No comments:

Post a Comment