简体   繁体   中英

Resume home Activity when certain TabSpec of TabActivity clicked

I have 2 main activities in my application. Lets call them Home and Tabs.

In Home there is a search EditBox and a list of the results.

In Tabs there are 2 significant tabs: details of a product and a list of similar products.

The problem is that you can easily loop here by clicking: productA -> similar -> productB -> similar -> productA -> ...

It's all fine until you want to go back to the Home again for a new search. Using back button will require a few clicks.

Tabs has the android:noHistory="true" attribute in manifest.

What I figured out was to add a third tab to Tabs which should reopen Home activity. I just overridden the onResume method.

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();

    Intent myIntent = new Intent(getBaseContext(), Home.class);
    startActivityFromChild(this, myIntent, 0);  
    finishFromChild(this);
}

The result is that clicking search tab starts a new Home activity (search field is empty) and if I than click back button it redirects me to Home activity once more, but this time there is text in the search field.

What I need is the activity with search field filled with recently typed text just after search tab is clicked. Also clicking back button in Home activity should not reopen it but just close the application.

Btw. If you have a better idea than this additional search tab please share with me :)

Cheers

It was as easy as:

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();

    finish();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM