There is already a backhandler component in the Appstore for what you describe.
If you still wish to create your own, there is documentation to help you get started with building widgets.
Good luck!