Tutorial on Hardware Back Button

Is there any tutorial on how to implement the hardware back button with unique functionality for each page.
Right now I am having a lot of trouble integrating it differently for each page or view.