Android activity restart

后端 未结 3 2033
醉梦人生
醉梦人生 2020-12-17 05:17


I am having a confusion in restarting an activity.. I have two function that works well for the same task. Please guide me which is best and why?

publ         


        
相关标签:
3条回答
  • 2020-12-17 05:58

    This has been posted before:

    Intent intent = getIntent();
    finish();
    startActivity(intent);
    
    0 讨论(0)
  • 2020-12-17 06:02

    I think this is a cleaner way for your requirement.

        Intent intent = getIntent();
        overridePendingTransition(0, 0);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        finish();
        overridePendingTransition(0, 0);
        startActivity(intent);
    
    0 讨论(0)
  • 2020-12-17 06:13

    Activities in the system are managed as an activity stack. When a new activity is started, it is placed on the top of the stack and becomes the running activity -- the previous activity always remains below it in the stack, and will not come to the foreground again until the new activity exits.

    for more info see Activity

    0 讨论(0)
提交回复
热议问题