Saturday, March 22, 2014

My First GitHub Project!

Been sitting on this app since last year, and I've been busy with other projects and work and just haven't had the time to finish it. Also thought this was the perfect time to begin my contribution to the open source community(aside from StackOverflow).

You can find it on GitHub

It's just an ambitious music player that uses a couple libraries. Nothing special. I thought this would  be a good resource for beginners to check out. However, there are a few things wrong with the current design and I tried to address them in the comments as well as below.


1) Use a Bound Service instead for music playback
At the time, I created a background service to handle the playback and made it a singleton, and whenever I needed to get a hold of it I'd just call Service.getInstance() from my Activity/Fragment or whatever to control the playback. You don't want to do this. Instead, use a [Bound Service](http://developer.android.com/guide/components/bound-services.html), and register your Activity or Fragment as clients using a binder and service connection. The developer guide explains this idea in detail and I came across it a couple months after I had started my horrible implementation. It's all a learning process though.

2) There's currently no mechanism to manage the lifecycle of the AsyncTasks, or to check if they are finished doing their jobs. This can cause nasty memory leaks as you're navigating between fragments and firing off new tasks before a previous one is finished.


3) I was using [LRU caches](http://developer.android.com/reference/android/util/LruCache.html) to cache the images(album art, genre art, etc). At that point I was allocating 1/8 of the apps heap memory for the cache, [as recommended](http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html). You might want to use another image caching library if you think it would be more optimal.


Feedback, thoughts, or contributions always welcome. I started this project almost a year ago without any intention of open sourcing it, so please excuse the lack of comments etc.

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Web Host