Copy from http://www.vogella.com/articles/AndroidServices/article.html