質問

I have a TabActivity, and I want to re-create the activity with the tab is visited(calling the content of onCreate() each visit) . how ?

役に立ちましたか?

解決

You could use ....

this.finish(); // this is instance of TabActivity

.... to close the current one and create a new intent using

Intent intent = new Intent(this, TabActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 
startActivity(intent);

Edit: Intent.FLAG_ACTIVITY_CLEAR_TOP seems in fact to work as well will probably not work, because though it is intended to bring an existing activity is just brought to front (without recreation).

Check out this for more.

Cheers!

他のヒント

public void onResume()

This method is called every time an activity comes to the foreground. So all you need to do is to override this method

public void onResume(){
    super.onResume();
   // do your stuffs
}

TO learn more about activity lifecycle see this document

Now you want to call onCreate each time, it seems you have some initializing task each time the acitivity comes to the foreground. So My suggestion is to use the initialization things in onResume instead of onCreate.

Before starting intent of each Tab, set Intent flag "clear top".

i.e

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

check my answer for reference in this question activity-in-tabactivity-doesnt-run-oncreate-method-when-clicked-second-time

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top