смотри у меня в MainActivity есть <com.jetradarmobile.snowfall.SnowfallView…
- User
смотри у меня в MainActivity есть <com.jetradarmobile.snowfall.SnowfallView android:id="@+id/snow" и во Фрагменте Profile есть switch1 мне нужно сделать так если я нажимаю на свитч то снег становиться видимым и при перезапуске сохраняет свое состояние а если я выключаю свитч то снег пропадает <Switch android:id="@+id/switch1"package com.example.cardsbattle.utilites;
import android.content.Context; import android.content.SharedPreferences;
import com.example.cardsbattle.utilites.Constants;
public class PreferenceManager { private final SharedPreferences sharedPreferences; public PreferenceManager(Context context){ sharedPreferences = context.getSharedPreferences(Constants.KEY_PREFERENCE_NAME, Context.MODE_PRIVATE);
} public void putBoolean(String key, Boolean value){ SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putBoolean(key, value); editor.apply(); } public Boolean getBoolean(String key) { return sharedPreferences.getBoolean(key, false); } public void putString(String key, String value) { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(key, value); editor.apply(); } public void putInt(String key, int value) { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putInt(key, value); editor.apply(); } public int getInt(String key) { return sharedPreferences.getInt(key, 0); // Возвращает 0, если ключ не найден } public String getString(String key) { return sharedPreferences.getString(key, null); } public void clear() { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.clear(); editor.apply(); } public void putLong(String key, long value) { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putLong(key, value); editor.apply(); } public long getLong(String key, long defaultValue) { return sharedPreferences.getLong(key, defaultValue); } public void putBestDrop(String key, String value) { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(key, value); editor.apply(); } public String getBestDrop(String key) { return sharedPreferences.getString(key, null); }}
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.