The Android sample code with comments edited by Shiyao Qi