zoukankan      html  css  js  c++  java
  • 防止事件导致的oncreate的多次调用

     <activity android:name=".Main"
                      android:label
    ="@string/app_name" android:configChanges="orientation|keyboardHidden">

    public void onConfigurationChanged(Configuration newConfig) {

            
    super.onConfigurationChanged(newConfig);
    }

    现在笔者正在moto702上测试游戏demo,突然发现滑盖会导致当前Activity多次调用oncreate事件。由于游戏的surfaceview是这里初始化的,所以多次的调用一定会给游戏本身带来多次的初始化。怎么解决呢 在AndroidManifest.xml中修改如上xml的内容android:configChanges
    ="orientation|keyboardHidden"并且在当前Activity中重载方法onConfigurationChanged,有需要的可以在方法中实现自己的功能。如:

    /*
             * 
             * if (this.getResources().getConfiguration().orientation ==
             * Configuration.ORIENTATION_LANDSCAPE) {
             * 
             * }
             * 
             * else if (this.getResources().getConfiguration().orientation ==
             * Configuration.ORIENTATION_PORTRAIT) {
             * 
             * }
             
    */
  • 相关阅读:
    使用ConcurrentHashMap需要知道的细节
    并查集(Union-Find)
    LeetCode2
    补充之前博客的几种排序--希尔排序、堆排序、归并排序
    左式二叉堆
    优先队列的一种实现--堆ADT
    开放地址法散列表ADT
    分离链表法散列ADT
    AVL树
    二叉查找树ADT--C语言描述
  • 原文地址:https://www.cnblogs.com/tt_mc/p/1921671.html
Copyright © 2011-2022 走看看