TabHost.setCurrentTab(index) work for first time

I created TabActivity having two tabs with two activities. one is login tab another is welcome tab.

user should not go welcome tab unless login successfully.if he tries to select welcome tab he throws to login tab.i use tabHost.setcurrenttab(index).

But when i click direct welcome tab it works fine for first time. When i again click tab rapidly it opens welcome tab.

Here is my code:

public void onCreate(Bundle savedInstanceState) {
            SharedPreferences mPreference = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
            username = mPreference.getBoolean("valid", false);
            Toast.makeText(this, "In Create", Toast.LENGTH_SHORT).show();
           //login sucessful            

on onResume, i repeat the same code.


Try this in your TabActivity. This is to prevent user to switch tab if he is not logged in.(I have no time to check it now,please let me know if any issue is there with the code):

SharedPreferences mPreference;


    mPreference = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    tabHost.setOnTabChangedListener(new OnTabChangeListener() {

    public void onTabChanged(String arg0) {

                username = mPreference.getBoolean("valid", false);
                if(user is logged in){
                     tabHost.setcurrenttab(0);//welcome page
                     tabHost.setcurrenttab(1);//login page

Need Your Help

Removing non-unique data on insert

c# database linq-to-sql

Table entity column is unique, and I'm trying to add items. Items amount is fairly big, so i'm trying to avoid connecting to a database many times. What is the best way to ignore duplicates?

TFS Modify Merge With Delete To Become Merge Without The Delete

visual-studio-2010 visual-studio-2008 merge tfs2010 bids

I ran into a problem trying to merge from integration to feature branch.