I am using cocos2dx to make a small game and in the activity of my game i give the following functions to handle back button.
@Override public boolean onKeyDown
Here's an update for Cocos2d-x version 3+
This has been answered simply (and works) here
as well as a slightly less complete youtube here