question: private void restoreActivityList ( ) { boolean isMapDirty = false ; mActivityList . clear ( ) ; Set < Integer > availableWebapps = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < NUM_WEBAPP_ACTIVITIES ; ++ i ) { availableWebapps . add ( i ) ; } SharedPreferences prefs = mContext . getSharedPreferences ( PREF_PACKAGE , Context . MODE_PRIVATE ) ; try { final int numSavedEntries = prefs . getInt ( PREF_NUM_SAVED_ENTRIES , 0 ) ; if ( numSavedEntries <= NUM_WEBAPP_ACTIVITIES ) { for ( int i = 0 ; i < numSavedEntries ; ++ i ) { String currentActivityIndexPref = PREF_ACTIVITY_INDEX + i ; String currentWebappIdPref = PREF_WEBAPP_ID + i ; int activityIndex = prefs . getInt ( currentActivityIndexPref , i ) ; String webappId = prefs . getString ( currentWebappIdPref , null ) ; ActivityEntry entry = new ActivityEntry ( activityIndex , webappId ) ; if ( availableWebapps . remove ( entry . mActivityIndex ) ) { mActivityList . add ( entry ) ; } else { isMapDirty = true ; } } } } catch ( ClassCastException exception ) { mActivityList . clear ( ) ; availableWebapps . clear ( ) ; for ( int i = 0 ; i < NUM_WEBAPP_ACTIVITIES ; ++ i ) { availableWebapps . add ( i ) ; } } for ( Integer availableIndex : availableWebapps ) { ActivityEntry entry = new ActivityEntry ( availableIndex , null ) ; mActivityList . add ( entry ) ; isMapDirty = true ; } if ( isMapDirty ) { storeActivityList ( ) ; } }
target:  Restores/creates the mapping between webapps and WebappActivities. The logic is slightly complicated to future-proof against situations where the number of WebappActivities is changed.