Skip to content

Commit 0af33c6

Browse files
committed
* Prevent GC from collecting function
1 parent 959eee5 commit 0af33c6

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

app/src/main/java/com/codedead/advancedportchecker/gui/activity/SettingsActivity.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public class SettingsActivity extends AppCompatActivity {
2828
@Override
2929
protected void onCreate(Bundle savedInstanceState) {
3030
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
31-
sharedPreferences.registerOnSharedPreferenceChangeListener((sharedPreferences, key) -> onSharedPreferenceChanged(key));
31+
32+
sharedPreferences.registerOnSharedPreferenceChangeListener(listener);
3233
LocaleHelper.setLocale(this, sharedPreferences.getString("appLanguage", "en"));
3334

3435
resetTitle();
@@ -44,24 +45,15 @@ protected void onCreate(Bundle savedInstanceState) {
4445
}
4546
}
4647

47-
/**
48-
* Method that is called when the value of a key inside the SharedPreferences changes
49-
*
50-
* @param key The key of the value that was changed
51-
*/
52-
private void onSharedPreferenceChanged(String key) {
53-
if (key.equals("appLanguage")) {
54-
changeLanguage();
48+
private final SharedPreferences.OnSharedPreferenceChangeListener listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
49+
@Override
50+
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
51+
if (key.equals("appLanguage")) {
52+
LocaleHelper.setLocale(getApplicationContext(), sharedPreferences.getString("appLanguage", "en"));
53+
recreate();
54+
}
5555
}
56-
}
57-
58-
/**
59-
* Change the language of the activity
60-
*/
61-
private void changeLanguage() {
62-
LocaleHelper.setLocale(getApplicationContext(), sharedPreferences.getString("appLanguage", "en"));
63-
recreate();
64-
}
56+
};
6557

6658
/**
6759
* Reset the title of the activity

0 commit comments

Comments
 (0)