Определите Int, чтобы быть в курсе текущей вкладки в классе:
public static SharedPreferences mSetupSharedPreferences;
public static final String CURRENT_TAB = "currentTab";
private static final in mCurrentTab;
Используйте общие предпочтения, чтобы сохранить эту mCurrentTab навсегда, поместите этот код в OnCreate():
mSetupSharedPreferences = getSharedPreferences(SETUP_PREFERENCES,
Context.MODE_PRIVATE);
// If it does not contain the CURRENT_TAB then create one
if (! mSetupSharedPreferences.contains(CURRENT_TAB)) {
SharedPreferences.Editor setup_editor = mSetupSharedPreferences.edit();
setup_editor.putInt(CURRENT_TAB, 1); // 1 means the current tab number is 1
setup_editor.apply();
}
Теперь сохраните cu Вкладка всякий раз, когда ко в ой то пользователь переключает вкладки:
SharedPreferences.Editor editor = mSetupSharedPreferences.edit();
editor.putInt(CURRENT_TAB, current_tab);
И когда пользователь нажимает кнопку назад, то прочитайте текущую вкладку и установите вид:
int currentTab = mSetupSharedPreferences.getInt(CURRENT_TAB, 0)
switch (currentTab) {
case 1: // Switch tab view here to 1
break;
case 2: // Switch tab view here to 2
break;
case 3: // Switch tab view here to 3
break;
}