Reloading an activity in Android

来源:互联网 发布:石油大学华东网络教育 编辑:程序博客网 时间:2024/05/20 09:26
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:
</pre><pre name="code" class="java">Intent intent = getIntent();overridePendingTransition(0, 0);intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);finish();overridePendingTransition(0, 0);startActivity(intent);


0 0