Android: Black Screen between Activity

后端 未结 5 429
误落风尘
误落风尘 2021-01-05 06:45

When I go one activity to another activity , between the transaction a Black screen is come for some seconds. I properly finish the activity before calling startActv

5条回答
  •  失恋的感觉
    2021-01-05 07:07

    If you have a finish() or FLAG_ACTIVITY_CLEAR_TASK - a blank screen may show up on pre ICS devices

    To avoid this black screen you have to add one line in intent

    overridePendingTransition (0, 0);
    

    Example(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)
    

    Example(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);
    

提交回复
热议问题