How to finish current activity in Android

前端 未结 8 1442
长发绾君心
长发绾君心 2020-11-28 03:19

I have an Android application. I am making a loading screen with a progress bar.

I entered a delay in the onCreate method. When the timer finishes, I want to finis

8条回答
  •  时光说笑
    2020-11-28 03:41

    When you want start a new activity and finish the current activity you can do this:

    API 11 or greater

    Intent intent = new Intent(OldActivity.this, NewActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
    

    API 10 or lower

    Intent intent = new Intent(OldActivity.this, NewActivity.class);
    intent.setFlags(IntentCompat.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
    

    I hope this can help somebody =)

提交回复
热议问题