I created a tabbed application in which I have three tabs.
In the first activity I am opening a class named Home.class and inside the Home.class I want to start another activity that should open in that tab itself is it possible.
Please help.
ActivityGroup is deprecated, try to use Fragment and FragmentManager
To start multiple Activity in one tab, you need to extend your tab with ActivityGroup. and when are you starting new Activity you need to use startChildActivity
Use Android ActivityGroup within TabHost to show different Activity
Related
I need to do a Fragment that works for all activities (like a banner or something).
I have a HomeActivity, IncidentActivity, ScheludeActivity, etc. but I need to do a fragment or something that could be accessed from all those activities but it need to be instantiate once because it will have a, webview that I don't want to be reloading everytime I change of activity.
Can you give me some advise?
You can create a BaseActivity which these three activities extend from this. The instance of fragment should be single. Your fragment should be retainable(setRetainInstance(true)). Do not forget, you should use the same instance of your Fragment! So, you can control fragment instance in your BaseActivity.
In MainActivity.java, I extends TabActivity to use Tabhost.
public class MainActivity extends TabActivity
In each Tab, I use ActivityGroup to manage some child activity
public class MerchandiserTabGroupActivity extends ActivityGroup
In a child activity A, I want to start another child activity B.
Intent intCreateClaim = new Intent(mContext, MultiPhotoSelectActivity.class);
startActivityForResult(intCreateClaim, Parameter.ACTIVITY_SELECT_IMAGE);
After I call setResult(RESULT_OK) and finish() in Activity B, onActivityResult() in Activity A isn't called.
Can anyone helps me? Thanks in advance.
I know this isn't really the answer you're looking for, but you're using deprecated API. You should try a refactor and use the new Fragment API and the v4 support library if you need to support older versions of Android too. Using fragments you won't need to rely on setResult and onActivityResult.
Fragment
Fragment Tab Host
This happens because after B activity finishes, Android returns to your TabActivity, not your A activity.
Use fragments. This way you will not have to deal with multiple activities. You will have only one parent activity with fragments inside. To make your life easier and to add support for pre-ICS Android devices, try GrilledUI library.
I have a activity Main which extends from SherlockFragmentActivity. In this activity Main, I have 3 tabs(Tab1, Tab2 and Tab3), they extend from SherlockFragment.
Now, How to launch Main's the Tab3 when I click at a button from other activity.
You can pass some extra params in the intent you are using to start the activity Main. You can do something like intent.putExtra(key,value), and after that in the Main activity inside onCreate() you can do getIntent.getExtras() and you will be able to start whatever fragment you want
In first activity
intent.putExtra("tabs", 2);
In activity with tab:
int tab_index = getIntent().getExtras().getInt("tab",0);
tabs.setCurrentTab(tab_index);
I have a TabActivity and inside 5 tabs with 5 activities each one. I want to set one of my tabs but not from the TabActivity(clicking on the tab on the top) but from an activity of any tab, for example clicking on a button of activity 3(which is asociated with the 3rd tab).
In my TabActivity there is a variable mTabhost, which I can use to set the selected tab with
mTabHost.setCurrentTab(0);//home
I guess I need access to that variable from Activity1-2-3-4, and doing that variable static doesnt work.
Say you have a MyTabActivity as TabActivity, which hosts 5 Activity(ies).
If you want to change the Tabs inside SecondActivity, you would write the code something like this.
MyTabActivity myTabs = (MyTabActivity) this.getParent();
Here you have your MyTabActvity
you can change the tabs like:
myTabs.getTabHost().setCurrentTab(index);
Save this mHost var instance in singleton class say Utility class . Then access particular var from Utility Class in different activity and set it accordingly. It works. I 've used it in my several projects.
I have an Android application which has four tabs (I use a main TabActivity with TabHost and TabSpecs).
In one of my sub activity (activity opened in a tab), i need to open a tab not by clicking on the tab title and i don't know how to do this.
For example, i have a button in my activity and when i click on it, it opens a different tab.
For the moment, it is what i do:
Intent intent = new Intent(myActivity.this, myTabActivity.class);
intent.putExtra("ComeFrom", true);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Then in the TabActivity, if i get true reading the "ComeFrom" extra i open the wished tab but the problem is that it kills all the other activies. So, if someone knows a better (cleaner) way to do that trick, please tell me...
Found an easier (I think) answer:
on the TabActivity declare a public, static and self variable and populate it on the onCreate method. F.e.:
public class TheActivity extends TabActivity {
public static TheActivity self;
...
#Override
public void onCreate(Bundle savedInstanceState) {
self=this;
on any Activity running in a tab, when you want to change the one shown on your app. you can do this:
TabHost tabHost = TheActivity.self.getTabHost();
tabHost.setCurrentTab(0);
Worked ok for me, hope serves someone else!
You have to use TabHost's "setCurrentTab(...)" for that. In one of my projects, I created a static method in the main Activity (the one with the TabHost), named "swtichToTab(int tab)". In my subactivites (those inside the tabs) could then just call "MainActivity.switchToTab()" to trigger switching.
It may not be the cleanest method, I'm sure you can achieve this using broadcast intents too.
You can create a BroadcastReceiver and send a broadcast with the index of the tab as extra
You can use views instead of activities for the content of the tabs. This way, the code is simpler and doesn't use as much memory. Plus, you then can use the setCurrentTab(tabIndex) method to easily switch between views.
I have a simple tutorial here. It has a tab activity with a list and map view. When you you click on an item in the list, the activity dynamically goes to the map view (using the setCurrentTab(tabIndex) method). You can easily modify this to have a button switch views.