ShareMarketActivity.java this handles the tabs, Tab1, Tab2, Tab3.java files..... which on load it load the 1st tab
in Tab3 (portfolio) when u click on the company it moves to another window, what i want to do is,when u click back button on the new window... it should again load the tabs and it moves to the Tab3.
back.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent("android.intent.action.ShareMarketActivity"));
}
});
So this will load the tabs again and show the tab1 as the starting tab. Not the Tab3. what i want is... ** load the ShateMarketActivity and straight away moves to tab3 ** ( in the 1st load i want Tab1 to be the 1st load not tab3)
You can use the setCurrentTab method of the tab host.
mTabHost.setCurrentTab(2);
What you need to do is listed briefly below. I am not putting any code though but it should be straightforward.
When you are navigating to a new window do not navigate through the child activities that reside in the TAB Host. Call getParent() and then start new Activity from the TabActivity which is the Parent.
Make the Tab launchmode in manifest as SingleTask.
You can not capture the result of the Activity in onActivityResult in TabHost and then call the child Activity to propogate the result by using getCurrentActivity()
The reason for the behavior you see is that Tabs are actually an ActivityGroup with multiple activities embedded in them for each TAB. Once you call a new Activity from any of the child Activity and then come back the Activity stack loses the Activity Group and lists the calling activity as parent and hence you just see TAB3 activity as the only activity.
Let me know if this does not help.
Related
I have this android app in which my main activity HomeActivity holds two fragments using a ViewPager and a tab layout. Each fragment holds a list of items and when clicked takes the user to another activity. Now I would like to return to the previous tab layout when the back button is pressed in the current activity. Simply put how do I get back to the tab layout from which the user had come from. Normally a back press would take the user to a default tab, in this case the BtcFragment tab but I would like to be able to return the user to the originally clicked tab in the HomeActivity.
in your Main Activity or where you define your view pager create a static method as below :
public static void ViewPagerTabSelector(int tabNumber) {
mViewPager.setCurrentItem(tabNumber);
}
then from activity you want to back in your `onbackpress call:
#Override
public void onBackPressed() {
MainActivity.ViewPagerTabSelector(0);
}
There are two activities.
Activity A has a button that can switch to Activity B.
Activity B also has a button that can switch to Activity A.
here is my code,
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
Log.e("current", context.getClass().toString());
Log.e("changeto", tab.getTag().toString());
if(context.getClass()==tab.getTag())
return;
Intent intent = new Intent(new Intent(context,(Class<?>) tab.getTag()));
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
context.startActivity(intent);
}
I want to remove the animation when i switch the activities, but it doesn't work.
However if I remove
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
it works perfectly. Why?
Sorry for my bad English.
In the Activity that you're switching to, try using overridePendingTransition(0,0); either in onResume or in onCreate.
If you're calling startActivity in a tab switch, you're doing it wrong. Tabs are for switching views within the current activity, and switching tabs should never create navigation history. Consider switching a fragment or replacing your view hierarchy with the newly selected tab's content instead.
The more you pursue a path of switching activities for tab selection, the more you will find yourself playing whack-a-mole with subtle user experience bugs that make your app simply feel "wrong."
With your proposed implementation above, the Back button will return to the previously selected tab, breaking the, "never creates navigation history" rule. You may think that finish()ing the current Activity as you start the next can solve this, but you'll still have a host of other issues. Users expect subtle elements of state such as scroll position to persist across tabs. As of Android 4.0 there is an expectation that users should be able to swipe horizontally between tabs (http://developer.android.com/design/building-blocks/tabs.html) which you will not be able to accomplish if you are using separate activities for each tab's content.
This is only a small sample, the list just goes on. Tabs should not be used to switch between different Activities.
I want to know how to clear child activities and how to invoke the parent activity of a particular tab on its second click (tab functionality like on iPhone?). I want to invoke the click listener for each tab. Assume as if the application gets deeper while using, it's hard to use the back button often to reach the parent activity. So i need to invoke the parent activity by clicking the tab.
On first tab it is working fine, here is the code
getTabWidget().getChildAt(0).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (getTabHost().getCurrentTabTag().equals("gebrauchte")) {
Intent intent = new Intent(getApplicationContext(),TabHome.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else{
tabs.setCurrentTab(0);
}
}
});
I tried to use the same code for the second tab with getChildAt(1), should i give TabHome class for all intent, if I try to give their respective class of 2nd, 3rd and 4th tab, the tabHost gets hidden.
You don't need to set onClickListener on Tabs. I would advice to use Android Tabs with Fragments
I have an application first showing a login screen which on a succesful login changes to a tab view with 3 tabs. Each tab is containing a different activity. When I switch between the tabs I would like the back button to return to the previous tab instead of the login screen.
How should the be done? I'm considering implementing onBackPressed on the tab view and remembering the tab-stack manually but I don't feel that is the right approach.
Let say you have tabs created in class called Main.java. Create there method like this:
public void switchTab(int tab) {
tabHost.setCurrentTab(tab);
}
which will change current tab. Next in activity where you want to change navigation insert the following code:
#Override
public void onBackPressed() {
Main m = (Main)getParent();
m.switchTab(0);
}
This should work.
I have created two tabs, say TAB1 and TAB2. For TAB1, i have loaded one Activity, say ActivityOne, into TAB1 as
Intent intent = new Intent(this,ActivityOne.class);
TabHost.TabSpec spec = getTabHost().newTabSpec("ActivityOne")
.setIndicator("Activity One",getResources().getDrawable(R.drawable.artists)).setContent(intent);
getTabHost().addTab(spec);
This ActivityOne has extended the ActivityGroup and i added one button in this activity. By clicking on this button it will call another activity, say ActivityOne_One, as
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(ActivityOne.this,ActivityOne_One.class);
replaceContentView("ActivityOne_One",intent);
}
public void replaceContentView(String id, Intent intent){
View view = this.getLocalActivityManager().startActivity(id, intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
this.setContentView(view);
}
When we click on that button ActivityOne_One will be launched under same TAB1. In this application i have two problems:
1) If i want to go back to ActivityOne under same TAB1 by using traditional BACK button on emulator it is not working..
2)ActivityOne_One is launching with no animation(like sliding from right to left) effect.
If anyone know about any one of these, give your advice..
Thanks,
venu
I have found the solution for my question. The following blog gave me a route for this
http://ericharlow.blogspot.com/2010/09/experience-multiple-android-activities.html
see this link which may help you out with this. http://blog.henriklarsentoft.com/2010/07/android-tabactivity-nested-activities/
i have implemented what is advised in the link i provided. it works OK, but it is quirky and does not always redirect you BACK like you would expect. i have found that you must implement your own custom tabs to really get this desired effect.