Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8352129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:52:39+00:00 2026-06-09T08:52:39+00:00

I am using ActionBar Tabs in Android 4 . I have 5 Broadcast receivers

  • 0

I am using ActionBar Tabs in Android 4. I have 5 Broadcast receivers, and all of them updates the part of UI. There are two Tabs in my app, both the tabs have different UI associated(that is, both tabs have different xml files associated with them, which will be inflated according to tab selection). For each Tab I am inflating a fragment.

Initially, I am showing only one tab. On clicking a button from the UI associated with that tab, I add another tab and I receive 5 broadcast receivers. I get broadcast receivers in any order. Now say there are following broadcast receivers: A B C D E

A, B, D and E updates the UI which is part of Tab 1.   

C updates the UI which is part of Tab 2.

Whenever a new tab is created, its UI gets replaced with previous tab’s UI, so when, say A and B gets called, they update the UI which is from Tab 1, but when C is received, the UI is now replaced with Tab2’s UI, and it updates the UI, but when D and E is received, they try to update the UI of tab 1, but since tab 2 is now inflated, I get null pointer exception on that statement on which D and E tried to make change.

So please tell me, how should I update my UI according to the broadcasters?

UPDATE: Now, I am getting NPE on following: This is inside one of my receiver, here I am creating new tab and want to insert a table from the broadcast receiver.

ActionBar actionbar = getActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab bTab = actionbar.newTab().setText("B");
bFragment = new BFragment();
bTab.setTabListener(new MyTabsListener(bFragment));
actionbar.addTab(bTab, true);

final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.mdsTable); // NPE linearLayout is not getting initialized.

I don’t understand why this is happening, since I have implemented MyTabsListener as:

class MyTabsListener implements ActionBar.TabListener {
    public Fragment fragment;

    public MyTabsListener(Fragment fragment) {
        this.fragment = fragment;
    }

    @Override
    public void onTabReselected(Tab tab, FragmentTransaction ft) {
        Toast.makeText(StartActivity.appContext, "Reselected!",
                Toast.LENGTH_LONG).show();
    }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        ft.replace(R.id.fragment_container, fragment);
    }

    @Override
    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        ft.remove(fragment);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:52:41+00:00Added an answer on June 9, 2026 at 8:52 am

    Here what I did is, first of all, whenever I receive Broadcast Receivers, I don’t update the UI in onReceive() method, instead I used to save the data that I receive into persistent storage.

    And based on the event, I used to create a new Tab. And now when user navigated to new Tab, the onCreateView() is called for that tab and I update the UI in this method.

    So no problem of:

    Whenever a new tab is created, its UI gets replaced with previous tab's UI, so when, say A and B gets called, they update the UI which is from Tab 1, but when C is received, the UI is now replaced with Tab2's UI, and it updates the UI, but when D and E is received, they try to update the UI of tab 1, but since tab 2 is now inflated, I get null pointer exception on that statement on which D and E tried to make change.
    

    since I update the UI in each onCreateView() method for each Tab.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using ActionBar Sherlock to implements tabs, I have a new TabsAdapter object declared and
My app is currently using the Fragments/v4 compatibility package to support Android versions all
I have an app that's built for Android 2.2, so I'm not using the
I am using ActionBarSherlock and have an ActionBar with navigation tabs in it. I
I have noticed that when using actionBar.setSelectedNavigationItem(x) in the onCreate() method of my Activity,
Is it possible to customize layout of android.widget.SearchView (I'm using it in actionBar)? I
I'm using the ActionBar. I'd like to have a refresh progress spinner on the
i'm using actionbar sherlock/fragments with my app my problem is that i need to
I am trying to hide the title part of my actionbar using ActionBarSherlock like
I'm using ActionBarSherlock to implement an ActionBar with tabs in my application. When I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.