Reloading an activity in Android

Manually reloading activity in Android application.

Wed, 13 Jul 2011

More often i wanted to reload an activity to refresh the contents of an page. I have seen many ways to do this in Android world and i always puzzled about the best approach.

However these are some of the approaches that i took . I found the following two approaches a lot cleaner as they kill the existing intent and restart.

Approach 1:

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

Approach 2:

Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG\_ACTIVITY\_NO\_ANIMATION);
finish();
overridePendingTransition(0, 0);
startActivity(intent);

Note: The second approach works only from API 5+

Loading...
Prasanna

Prasanna is a full stack web developer, loves to build user interfaces with Javascript. Considers himself as a geek, quick learner and a team player 😃

  • rants and writings through personal experience