Android Activity Launch


I got confused about restarting activity. I have two functions that work well for the same task. Please help me which is better and why?

public void restart()   
    {  
        Intent intent = getIntent();  
        overridePendingTransition(0, 0);  
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);  
        finish();  
        overridePendingTransition(R.anim.fade,R.anim.fade);
        startActivity(intent);

    }

or

public void restart()   
    {         
        onCreate();  
    }  

Thanks in advance?

+3
source share
3 answers

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);
+3
source

Actions in the system are managed as a stack of operations. When a new action begins, it is placed on the top of the stack and becomes the current action - the previous action always remains below it on the stack and will not return to the foreground until a new action is completed.

for more information see Activity

0
source

:

Intent intent = getIntent();
finish();
startActivity(intent);
0
source

All Articles