Updated Android code to handle cancel event properly