3


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?

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?

Anubhaw
  • 5,978
  • 1
  • 29
  • 38
GouravJn
  • 246
  • 1
  • 6
  • 18

3 Answers3

3

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);
Tanmay Mandal
  • 39,873
  • 12
  • 51
  • 48
0

This has been posted before:

Intent intent = getIntent();
finish();
startActivity(intent);
Community
  • 1
  • 1
Sathish
  • 1,455
  • 1
  • 16
  • 22
0

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

Niranj Patel
  • 32,980
  • 10
  • 97
  • 133
  • Thanks Sir for your response, but when I close the running activity it get killed normally without showing an extra-ordinary behaviour(in case of second option)... – GouravJn May 26 '11 at 06:17