How to avoid black screen when Intent.FLAG_ACTIVIT

2020-06-03 04:58发布

In my android app, I need to use Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK to set my intent flag. I can remove all my previous Activities and start a new Activity in this way.This is my code below:

Intent intent = new Intent(Gerenxinxi.this, MainPart.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
overridePendingTransition(0,0);

However,I found a flicker of black screen when i use the code above. If I don't set intent flag with Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK , the flicker of black screen will be gone.My question is: what can I do to avoid the black screen when Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK is set ?

Before I write down this question, I have found that someone has the similar question.This is the link However,the answers of this question can not solve my problem.So I ask the question again.I hope anyone can help me.Thank you.

4条回答
ら.Afraid
2楼-- · 2020-06-03 05:25

This initial screen that you see is called the "Preview" screen. You can disable this completely by declaring this in your theme:

android:windowDisablePreview

<style name="Theme.MyTheme" parent="android:style/Theme.Holo">
    <!-- This disables the black preview screen -->
    <item name="android:windowDisablePreview">true</item>
</style>
查看更多
乱世女痞
3楼-- · 2020-06-03 05:31

Try this

Intent intent = new Intent(Gerenxinxi.this, MainPart.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
查看更多
叛逆
4楼-- · 2020-06-03 05:37

Add this line in your style

android:windowDisablePreview = true.
查看更多
地球回转人心会变
5楼-- · 2020-06-03 05:45

only one solution i found it instead of showing black screen show app theme background. in my case its white

     <application

            android:name="com.my.MyApplication"

            android:allowBackup="true"

            android:icon="@drawable/launcher"

            android:label="@string/app_name"

            android:theme="@style/Theme.MyTheme”>


   <style name="Theme.MyTheme" parent="android:style/Theme.Holo">
        <!-- This disables the black preview screen -->
        <item name="android:windowDisablePreview">true</item>
    </style>
查看更多
登录 后发表回答