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.
The flags you can use to modify the default behavior are: FLAG_ACTIVITY_NEW_TASK. Start the activity in a new task. If a task is already running for the activity you are now starting, that task is brought to the foreground with its last state restored and the activity receives the new intent in onNewIntent() .
Use Intent Flags Intents are used to launch activities on Android. You can set flags that control the task that will contain the activity. Flags exist to create a new activity, use an existing activity, or bring an existing instance of an activity to the front.
This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent. # Start the activity connect to the # specified class Intent i = new Intent(this, ActivityTwo. class); startActivity(i);
Android Intent FLAG_ACTIVITY_CLEAR_TOP If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With