In my app I have a child class that extends a support library class called SearchFragment
in the leanback support library. I need to extend this class but unfortunately the onPause()
of the parent (SearchFragment
) class has a method I cannot use.
Every time I leave the activity the parent class runs the onPause()
which calls the method I don't want.
Is there a way I can extend the SearchFragment
class but not allow it to run its own onPause()
?
Here is the onPause()
method in the parent class that I cannot alter.
android.support.v17.leanback.app.SearchFragment
@Override
public void onPause() {
releaseRecognizer(); //Need to stop this from calling
super.onPause();
}
private void releaseRecognizer() {
if (null != mSpeechRecognizer) {
mSearchBar.setSpeechRecognizer(null);
mSpeechRecognizer.destroy();
mSpeechRecognizer = null;
}
}
Also, the reason I am doing this is because this is an Android TV > Fire TV port. Fire TV does not have a speechRecognizer.
Use Proguard assumenosideeffects
option to annihilate the call to releaseRecognizer() method inside SearchFragment. This will require you to compile your code with Proguard enabled, but since the code in question is invoked in somewhat specific scenario, you may get away with using Proguard in release builds only.
Note, that you have to enable optimizations (the dontoptimize
option must not be set), because stripping calls to methods via assumenosideeffects
is technically an "optimization".
Make sure to use suggestions in this answer to limit Proguard actions to specific classes you want to "optimize" (in your case — to android.support.v17.leanback.app.SearchFragment).
This is the only way to cope with your problem without modifying the source code of SearchFragment. On second thought, you may be better off simply copying necessary classes to your project or in the worst case — plugging entire leanback support library as Gradle submodule and modyfying necessary methods directly (there is a good chance, that Fire TV has other issues with it besides this one).