Merge pull request #3849 from Tsunamical/codecleanup [Android] Reduce code redundancy and catch a leak