【问题标题】:Android: Black Screen between ActivityAndroid:活动之间的黑屏
【发布时间】:2016-03-25 00:14:41
【问题描述】:

当我将一项活动转到另一项活动时,交易之间会出现黑屏几秒钟。我在调用 startActvity() 之前正确完成了活动。

我正在为我的活动使用 android:theme="@android:style/Theme.Translucent" 主题。即使在活动事务之间出现黑屏

谁能告诉我如何解决这个问题

提前致谢:)

【问题讨论】:

  • 您是否使用自定义过渡动画?我认为这可能会解决您的问题,使用淡出淡入淡出动画来查看它是否可以解决您的问题,看看stackoverflow.com/a/18475926/3065080
  • 我检查了自定义动画,甚至认为黑屏会持续几秒钟 @Mushroomzier
  • 尝试使用不同的主题或设备。只是为了找出导致黑屏的原因。如果我们找到原因,我们可以解决它☺

标签: android android-layout android-intent android-activity


【解决方案1】:

在调用 startActivity() 之前无需完成活动。

确保您已在调用的 Activity 的 onCreate 中设置内容视图,并且您没有阻塞 UI 线程(如果您已覆盖它们,请检查 onCreate、onStart 和 onResume)。

【讨论】:

    【解决方案2】:

    您不需要管理完成活动,当活动不再可见时,这将自动管理。只需使用:

    startActivity(new Intent(this, MyNextActivity.class));
    

    并在您使用的任何方法中使用此代码来导航活动更改。

    如果您确定您的窗口是您的活动的背景,您可以将窗口背景设置为黑色以外的颜色:

    <item name="android:windowBackground">@drawable/window_background</item>
    
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
        <solid android:color="@color/window_background"/>
    </shape>
    

    windowBackground in Android 6 (Marshmallow)

    另一个选项是管理转换,因此第一个转换的结束和第二个转换的开始之间没有间隙。但是,您没有提到转换。

    How to remove the delay when opening an Activity with a DrawerLayout?

    【讨论】:

      【解决方案3】:

      要禁用此默认动画,请创建一种样式:

      <style name="noAnimTheme" parent="android:Theme">
      <item name="android:windowAnimationStyle">@null</item>
      </style>
      

      并将其设置为清单中活动的主题:

      <activity android:name=".ui.ArticlesActivity" android:theme="@style/noAnimTheme">
      </activity>
      

      【讨论】:

        【解决方案4】:

        假设:-

        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.xyz);
        
            // comment code here
            }
        

        如果您从活动 A 转到 B,然后尝试在 OnCreate 中注释代码,在活动 B 中的 OnResume 像这样并检查仍然黑屏是否出现。如果出现然后尝试更改主题。

        【讨论】:

          【解决方案5】:

          如果您有 finish() 或 FLAG_ACTIVITY_CLEAR_TASK - ICS 之前的设备上可能会显示空白屏幕

          为了避免这个黑屏,你必须在意图中添加一行

          overridePendingTransition (0, 0);
          

          示例(kotlin):

          val intent = Intent(applicationContext, MainActivity::class.java)
          intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
          startActivity(intent)
          overridePendingTransition (0, 0)
          

          示例(Java):

          Intent intent = new Intent(getApplicationContext(), MainActivity.class);
          intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
          intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          startActivity(intent);
          overridePendingTransition (0, 0);
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-07-25
            • 1970-01-01
            相关资源
            最近更新 更多