0

This is my MainActivity.java:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    Resources ressources = getResources();
    TabHost tabHost = getTabHost();

    registerReceiver(myBroadcastReceiver1, new IntentFilter(
            MYBROADCAST_INTENTFILTER));

Intent intentFriends = new Intent().setClass(this,
                TabFriendsActivity.class).addFlags(
                Intent.FLAG_ACTIVITY_CLEAR_TOP);

        TabSpec tabFriends = tabHost
                .newTabSpec("Friends")
                .setIndicator("",
                        ressources.getDrawable(R.drawable.btn_tab_friends))
                .setContent(intentFriends);

        // Talks tab
        Intent intentTalks = new Intent()
                .setClass(this, TabTalksActivity.class).addFlags(
                        Intent.FLAG_ACTIVITY_CLEAR_TOP);
        TabSpec tabTalks = tabHost
                .newTabSpec("Talks")
                .setIndicator("",
                        ressources.getDrawable(R.drawable.btn_tab_talk))
                .setContent(intentTalks);

        // Add friends tab
        Intent intentAddFriends = new Intent().setClass(this,
                TabAddFriendsActivity.class).addFlags(
                Intent.FLAG_ACTIVITY_CLEAR_TOP);
        TabSpec tabAddFriends = tabHost
                .newTabSpec("Add friends")
                .setIndicator("",
                        ressources.getDrawable(R.drawable.btn_tab_addfriend))
                .setContent(intentAddFriends);

        // Other tab
        Intent intentOther = new Intent()
                .setClass(this, TabOtherActivity.class).addFlags(
                        Intent.FLAG_ACTIVITY_CLEAR_TOP);
        TabSpec tabSpecOther = tabHost
                .newTabSpec("Other")
                .setIndicator("",
                        ressources.getDrawable(R.drawable.btn_tab_other))
                .setContent(intentOther);

        // add all tabs
        tabHost.addTab(tabFriends);
        tabHost.addTab(tabTalks);
        tabHost.addTab(tabAddFriends);
        tabHost.addTab(tabSpecOther);

        // set Windows tab as default (zero based)
        tabHost.setCurrentTab(0);

        TabWidget tabs = (TabWidget) findViewById(android.R.id.tabs);
        badge = new BadgeView(this, tabs, 1);
        badge.setText("new");

    }

I want to show text "new" in tabTalks when I got message from GCM by BroadcastReceiver. I try to debug and got information of "intentChatting" that means BroadcastReceiver is working, but text "new" not show in tabTalks icon.

private BroadcastReceiver myBroadcastReceiver1 = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String intentChatting = intent.getExtras().get("Intent").toString();
            if (intentChatting != null) {
                pushBadge(intentChatting);
            }

        }
    };

    private void pushBadge(String intentChating) {
        badge.show();
    }

And this is my main_activity.xml:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#f2f2f2">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="462dp"
            android:layout_weight="0.07">
        </FrameLayout>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#000" />
    </LinearLayout>

</TabHost>

So, what wrong with my code. I want to show badge in tabhost when receiver message from GCMby BroadcastReceiver. But it's not work!

Any help much appreciated! Thanks.

Sami Eltamawy
  • 9,874
  • 8
  • 48
  • 66
snow bin
  • 31
  • 1
  • 5
  • https://github.com/jgilfelt/android-viewbadger. check this if it helps – Raghunandan Feb 18 '14 at 08:47
  • Thanks,but it's not work for me. – snow bin Feb 18 '14 at 08:49
  • As per my way you can store your tab layout view and `VISIBLE` and `INVISIBLE` you badge into your updates and you'll check your update into `onResume()` method of your `TabActivity` – M D Feb 18 '14 at 08:52
  • http://stackoverflow.com/questions/26402748/tabhost-android-viewbadger-badge-issue @Manish please have a look i am stuck here from last week please guide me and thanks in advance – Ali Ashiq Oct 20 '14 at 12:47

0 Answers0