现在我们开发一般大多用的导航框架 是 react-native-router-flux 和 react-navigation
这两个框架 很强大 但是在处理 android 按两次返回键退出当前应用程序时 确不尽如意。
终极万能适配解决方案
在原生MainActivity 中

public class MainActivity extends ReactActivity {    /**     * Returns the name of the main component registered from JavaScript.     * This is used to schedule rendering of the component.     */    private long firstTime = 0;    @Override    protected String getMainComponentName() {        return "demo46";    }    @Override    protected void onCreate(Bundle savedInstanceState) {//        RCTSplashScreen.openSplashScreen(this);   //open splashscreen        //  RCTSplashScreen.openSplashScreen(this, true, ImageView.ScaleType.FIT_XY);   //open splashscreen fullscreen        SplashScreen.show(this);        super.onCreate(savedInstanceState);        GetSmsFromPhone.initActivity(this);        NaviModule.initActivity(this);        PhoneMailList.initActivity(this);        //okhttp    }    @Override    protected void onPause() {        SplashScreen.hide(this);        super.onPause();    }    @Override    protected void onResume() {        super.onResume();    }    @Override    protected void onDestroy() {        super.onDestroy();        MoxieSDK.getInstance().clear();    }    @Override    public boolean onKeyDown(int keyCode, KeyEvent event) {        long secondTime = System.currentTimeMillis();        if (keyCode == KeyEvent.KEYCODE_BACK) {            if (secondTime - firstTime < 2000) {                System.exit(0);            } else {                Toast.makeText(getApplicationContext(), "再按一次退出应用程序", Toast.LENGTH_SHORT).show();                firstTime = System.currentTimeMillis();            }            return true;        }        return super.onKeyDown(keyCode, event);    }

重写onKeyDown方法 写上如上代码 就完美解决了。

更多相关文章

  1. android缓存框架ASimpleCache
  2. Android应用程序获取system权限
  3. Android获取桌面应用程序
  4. android 五大应用开发框架是什么
  5. Android单例关闭应用程序
  6. [Android] 开发资料收集:依赖注入框架
  7. android应用程序中获取view的位置(2)
  8. java android HTTP应用程序设计
  9. Android应用开发攻略

随机推荐

  1. StreamSet使用要点
  2. Python 如何爬取实时变化的 WebSocket 数
  3. 正式开始工作了,分享一点想法
  4. 在ADC设备上安装SSL证书时出现错误:“证书
  5. 编程老司机带你玩转 CompletableFuture
  6. 深入理解Shadow DOM v1[每日前端夜话0x63
  7. 机器学习算法之线性回归的推导及应用
  8. 老司机带你了解微信/支付宝支付的相关概
  9. 如何使用 SSH 远程控制一台 Windows 服务
  10. 高效开发!借助 Mac + Windows 实现八屏办