background a react-native android app using back button

前端 未结 2 1120
一整个雨季
一整个雨季 2020-12-06 08:10

I\'ve followed the example pattern for handling the android back button in the react-native docs and it works well. I can use the hardware back button to pop my navigation s

2条回答
  •  生来不讨喜
    2020-12-06 08:47

    Answered my own question. The trick is to override the default back button behaviour in the MainActiviy:

    public class MainActivity extends ReactActivity {
    
        @Override
        protected String getMainComponentName() {
            return "foo";
        }
    
        @Override
        public void invokeDefaultOnBackPressed() {
            // do not call super. invokeDefaultOnBackPressed() as it will close the app.  Instead lets just put it in the background.
            moveTaskToBack(true);
        }
    }
    

提交回复
热议问题