Search code examples
androidandroid-studioback-button

Overriding back button on android when it does not extends activity


Hi currently I'm having an augmented reality application and I'm using the open source code of DroidAR.

My problem right now is that in the augmented reality screen the code extends Setup ( which in provided by DroidAR ) instead of extends Activity like what we normally do. Thus when I wanted to override the back button I could not use onBackPressed. Is there any other way that I could override it?


Solution

  • Not familiar with DroidAR, but according to the source code of Setup, it has a "target" Activity that you pass as a constructor param (and can retrieve by calling getActivity()).

    I suppose you could just simply override onBackPressed() in the Activity you're passing to the constructor of Setup (and if you would like to call it explicitly, you could just invoke getActivity().onBackPressed()).