Different hardware back button callback for different controllers


i need to do different things on hardware back button click in different controllers. the problem is when using registerBackButtonAction in one controller seems to override the same action in all controllers.
i know i can put this code is app.run and check for state name, but i need to access some controller specific properties when clicking back button, so putting in app.run will not work for me.

can anyone help me with this?