padam thapa
padam thapa

Reputation: 1477

getLocalActivityManager().getActivity(tabTag) return NULL

I have 2 tabs with tagID "tag01" and "tag02". I have explicitly set the focus to first tab by calling tabHost.setCurrentTab(0)

When i call getLocalActivityManager().getActivity("tag01") i get the object of activity but when i call

getLocalActivityManager().getActivity("tag02") then i get NULL.
//Log.i("tab status: ", getLocalActivityManager().getActivity("tag02")+""); prints null
//Log.i("tab status: ", getLocalActivityManager().getActivity("tag01")+""); prints com.test.TestActivity@437c06c8

Now when i again run my app and this time click second tab and then getLocalActivityManager().getActivity("tag02") gives object (toString() in logcat). So after checking it again and again i found that "only activity in first tab( that i had set focus explicitly by tabHost.setCurrentTab(0)) returns non-null" and other tabs return null unless u don't click those tab. When i click all tabs i.e atleast i go through all tabs by clicking them then getLocalActivityManager().getActivity(anyTag) returns object(i am tracing toString()) . How to access activity from other tabs without clicking other tabs because user won't know that he/she has to click tabs. Please give some suggestions. Because i have to access activity in tabs in my app. I hope you understood my problem.

thanks

Upvotes: 0

Views: 3932

Answers (2)

user2330792
user2330792

Reputation: 67

i could able to get the activity instance with out running the for loop by setting the CurrentTab property value before calling getactivity function.

i.e

tabHost.setCurrentTab(i); //i index of anytab activity
getLocalActivityManager().getActivity(anyTag);

Upvotes: 0

Sherif elKhatib
Sherif elKhatib

Reputation: 45942

The activity is not created!

if you have n tabs You could do this in your onCreate():

for(int i=n-1;i>0;i--)
    tabHost.setCurrentTab(i);

In this way, the tab displayed is the first tab (with index 0) and getLocalActivityManager().getActivity(anyTag) will return non-null

Upvotes: 1

Related Questions