Passing ArrayList<String> between tabs

心不动则不痛 提交于 2019-12-01 00:57:27

What's about setting a static field into the myTabs object?

    public class myTabs extends TabActivity {
....
public static arrayPeople = new ArrayList<String>();
....

On TabOne.java:

 @Override
    public void onStop(){
       myTabs.arrayPeople = arrayPeople;
    }

On TabTwo.java:

arrayPeople =  myTabs.arrayPeople

Does make sense?

tony

With the examples above, it was really work when I replace the "onStop" = "onPause"

/** Called when the activity looses focus **/
@Override public void onStop()
{
    Intent myIntent = new Intent();
    myIntent.putStringArrayListExtra("arrayPeople", arrayPeople);
    this.setIntent(myIntent);
}

/** Called when the activity looses focus **/
@Override public void onPause()
{
    Intent myIntent = new Intent();
    myIntent.putStringArrayListExtra("arrayPeople", arrayPeople);
    this.setIntent(myIntent);
}

I don't think altering the intent in onStop() will work because the TabHost handles the intents. Setting one class' intent with this.setIntent() wont let another class access it with getIntent() as they are built on different intents.

I would either store my arrayPeople in a database or I would pass arrayPeople back to the TabHost with MyTabs.setArrayPeople or something similar. Then you can query the db onCreate of your next tab or just pull it from your MyTabs Class.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!