• <bdo id='6ymBA'></bdo><ul id='6ymBA'></ul>
    1. <i id='6ymBA'><tr id='6ymBA'><dt id='6ymBA'><q id='6ymBA'><span id='6ymBA'><b id='6ymBA'><form id='6ymBA'><ins id='6ymBA'></ins><ul id='6ymBA'></ul><sub id='6ymBA'></sub></form><legend id='6ymBA'></legend><bdo id='6ymBA'><pre id='6ymBA'><center id='6ymBA'></center></pre></bdo></b><th id='6ymBA'></th></span></q></dt></tr></i><div id='6ymBA'><tfoot id='6ymBA'></tfoot><dl id='6ymBA'><fieldset id='6ymBA'></fieldset></dl></div>
      <tfoot id='6ymBA'></tfoot>
    2. <legend id='6ymBA'><style id='6ymBA'><dir id='6ymBA'><q id='6ymBA'></q></dir></style></legend>

        <small id='6ymBA'></small><noframes id='6ymBA'>

      1. Android:屏幕旋转、销毁和服务难题

        Android: screen rotation, on destroy and services connundrum(Android:屏幕旋转、销毁和服务难题)
            <bdo id='0bvRC'></bdo><ul id='0bvRC'></ul>
            <i id='0bvRC'><tr id='0bvRC'><dt id='0bvRC'><q id='0bvRC'><span id='0bvRC'><b id='0bvRC'><form id='0bvRC'><ins id='0bvRC'></ins><ul id='0bvRC'></ul><sub id='0bvRC'></sub></form><legend id='0bvRC'></legend><bdo id='0bvRC'><pre id='0bvRC'><center id='0bvRC'></center></pre></bdo></b><th id='0bvRC'></th></span></q></dt></tr></i><div id='0bvRC'><tfoot id='0bvRC'></tfoot><dl id='0bvRC'><fieldset id='0bvRC'></fieldset></dl></div>
          • <small id='0bvRC'></small><noframes id='0bvRC'>

                <tbody id='0bvRC'></tbody>
              <legend id='0bvRC'><style id='0bvRC'><dir id='0bvRC'><q id='0bvRC'></q></dir></style></legend>

                <tfoot id='0bvRC'></tfoot>

                • 本文介绍了Android:屏幕旋转、销毁和服务难题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我已经修改了 SDK 演示中的蓝牙聊天示例,以便能够控制 arduino 供电的蓝牙 LED 矩阵.使用聊天程序,我可以通过蓝牙向显示器发送消息.我有一个问题.我做了两个屏幕布局,一个纵向和一个横向.这样,无论方向如何,我都可以让界面占据手机上的最大空间.

                  I've modified the bluetooth chat example from the SDK demos to be able to control an arduino powered bluetooth LED matrix. Using the chat program, I can send messages to the display via bluetooth. I have a problem though. I've done two screen layouts, a portrait and a landscape. This way I can have the interface occupy the most space on the phone, regardless of orientation.

                  问题在于,如果手机旋转,则会调用 OnDestroy() 来重新加载新布局(横向或纵向).在 OnDestroy() 例程中,我还会销毁蓝牙链接(如果已建立):

                  The problem is that if the phone is rotated, OnDestroy() is called, to reload the new layout (landscape, or portrait). In the OnDestroy() routine I also destroy the bluetooth link, if it is established:

                     public void onDestroy() {
                          super.onDestroy();
                          // Stop the Bluetooth chat services
                          if (mChatService != null)
                              mChatService.stop();
                          if (D)
                              Log.e(TAG, "--- ON DESTROY ---");
                      }
                  

                  阅读此处的其他帖子,我发现您可以通过在清单中添加android:configChanges="orientation""来防止服务停止.这样做,当我旋转屏幕时,我到显示器的蓝牙链接不再终止,但是现在屏幕不会在横向模式下重绘.

                  Reading other posts on here, I've found that you can prevent the service from being stopped by adding "android:configChanges="orientation"" to the Manifest. Doing this, when I rotate the screen, my bluetooth link to the display is no longer terminated, however now the screen doesn't redraw in landscape mode.

                  为了解决这个问题,我正在考虑删除if mchatservice..."部分,该部分会终止连接,但是当应用程序最终退出时,我仍然需要运行代码.

                  To fix this, I am thinking of removing the "if mchatservice..." section, which is terminating the connection, but then I will still need the code to run when the application is ultimately exited.

                  有没有办法在旋转时重绘屏幕而不终止连接?如果没有,我想我总是可以将服务代码移至 OnPause() 事件,但是如果应用失去前台焦点,这将终止连接.

                  Is there a way to have the screen redraw when rotated, without terminating the connect? If not, I think I can always move the service code to the OnPause() event, however this will terminate the connection if the app ever looses forground focus.

                  还有其他方法吗?

                  谢谢.

                  推荐答案

                  如果您将android:configChanges="orientation"" 添加到您的 Manifest 以防止 Activity 被销毁和重新创建,您可能需要实现方法:

                  If you add "android:configChanges="orientation"" into your Manifest to prevent the activity from being destroyed and re-created, you might want to implement the method:

                  public void onConfigurationChanged(Configuration newConfig)
                  

                  每次系统配置改变时都会执行此方法,即当您旋转手机并改变方向时.在此方法中,您可以为您的活动重新应用新布局:

                  This method is executed every time the system configuration is changed, i.e. when you rotate the phone and orientation is changed. Inside this method you can re-apply a new layout for your activity:

                  public void onConfigurationChanged(Configuration newConfig) {
                      super.onConfigurationChanged(newConfig);
                  
                      if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
                          Log.e(TAG, "ORIENTATION_LANDSCAPE");
                      } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
                          Log.e(TAG, "ORIENTATION_PORTRAIT");
                      }
                  }
                  

                  这篇关于Android:屏幕旋转、销毁和服务难题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
                  cocos2d-android: how to display score(cocos2d-android:如何显示分数)
                  Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
                  SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
                  Android file copy(安卓文件拷贝)
                  Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)
                  • <bdo id='jZNk7'></bdo><ul id='jZNk7'></ul>

                          <i id='jZNk7'><tr id='jZNk7'><dt id='jZNk7'><q id='jZNk7'><span id='jZNk7'><b id='jZNk7'><form id='jZNk7'><ins id='jZNk7'></ins><ul id='jZNk7'></ul><sub id='jZNk7'></sub></form><legend id='jZNk7'></legend><bdo id='jZNk7'><pre id='jZNk7'><center id='jZNk7'></center></pre></bdo></b><th id='jZNk7'></th></span></q></dt></tr></i><div id='jZNk7'><tfoot id='jZNk7'></tfoot><dl id='jZNk7'><fieldset id='jZNk7'></fieldset></dl></div>

                          <small id='jZNk7'></small><noframes id='jZNk7'>

                          <legend id='jZNk7'><style id='jZNk7'><dir id='jZNk7'><q id='jZNk7'></q></dir></style></legend>
                          <tfoot id='jZNk7'></tfoot>
                            <tbody id='jZNk7'></tbody>