Search code examples
androidandroid-tabactivity

Come back with last updated tab activity


When i come back from tab 1 with saving data and come on the my main tab activity so i come on the current tab 0 so how can i come back with my last updated tab activity ?

Thanks


Solution

  • You can use SharedPreferences At load time

    step 1 at load time Write SharedPreferences and store 0 values make sure its write one time

    step 2 Read that values from SharePreference and getting it

    stap 3 set values in like

     Boolean temp = true;
    
    if(temp)
        {
             SharedPreferences.Editor shedit=shreftab.edit();
             shedit.putString("tabchange", "0");
             shedit.commit();
             temp = false;
        }
    
             String  vartabis = shreftab.getString("tabchange", null);
             tabhost.setCurrentTab(Integer.parseInt(vartabis));
    

    step 4 now you can update it SharedPreferences file key values as per require and get it