There is a list of news, when you go to the news, the information in the new activation opens. I try to make it so that after the user read the news the title color changed. It was decided to replace the SharedPreference implementation SharedPreference a SQLite database.
First of all, I created the class TopStoryDatabaseHelper , where I save the Id :
public class TopStoryDatabaseHelper extends SQLiteOpenHelper { private static final String DB_NAME = "topstory"; private static final int DB_VERSION = 1; public TopStoryDatabaseHelper(Context context) { super(context, DB_NAME, null, DB_VERSION); } @Override public void onCreate(SQLiteDatabase sqLiteDatabase) { sqLiteDatabase.execSQL("CREATE TABLE TOPSTORY(" + " _id INTEGER PRIMARY KEY AUTOINCREMENT;) "); insertId(sqLiteDatabase); } @Override public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) { } private static void insertId(SQLiteDatabase sqLiteDatabase) { ContentValues idValues = new ContentValues(); sqLiteDatabase.insert("TOPSTORY", null, idValues); } } The logic is the same, the user clicks on the news - the news opens - the id is saved - after which the news is considered to be read - we change the color for the read news. So as the user adds the nth number of id, I would like to clarify 1. Do I need to add all the fields for my news to the database? 2. After that, how to select from the activit class by id correctly.
SharedPreferences, this solution will be wrong from the point of view of architecture , and if something changes, you will need to change everything drastically . And yes, save the state of each news with different keys. Will work ... for now. But this is not a good way to solve this kind of problems. - post_zeew