|  |  | 
 |  |  | package com.example.agvcontroller; | 
 |  |  |  | 
 |  |  | import android.content.SharedPreferences; | 
 |  |  | import android.os.Bundle; | 
 |  |  | import android.util.Log; | 
 |  |  |  | 
 |  |  | 
 |  |  | import androidx.recyclerview.widget.LinearLayoutManager; | 
 |  |  | import androidx.recyclerview.widget.RecyclerView; | 
 |  |  |  | 
 |  |  | import com.google.gson.Gson; | 
 |  |  | import com.google.gson.reflect.TypeToken; | 
 |  |  |  | 
 |  |  | import java.lang.reflect.Type; | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.List; | 
 |  |  |  | 
 |  |  | 
 |  |  |     private RecyclerView recyclerView; | 
 |  |  |     private List<Item> items; | 
 |  |  |     private EditeAdapter adapter; | 
 |  |  |     private SharedPreferences sharedPreferences; | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     protected void onCreate(Bundle savedInstanceState) { | 
 |  |  |         super.onCreate(savedInstanceState); | 
 |  |  |         setContentView(R.layout.activity_edite); | 
 |  |  |  | 
 |  |  |         items = new ArrayList<>(); | 
 |  |  |         sharedPreferences = getSharedPreferences("AGVControllerPrefs", MODE_PRIVATE); | 
 |  |  |  | 
 |  |  |         items.add(new Item("Item 1", "Description 1", 10, "1", 0)); | 
 |  |  |         // Load items from SharedPreferences | 
 |  |  |         items = loadItemsFromSharedPreferences(); | 
 |  |  |  | 
 |  |  |         recyclerView = findViewById(R.id.edite_recyclerView); | 
 |  |  |         recyclerView.setLayoutManager(new LinearLayoutManager(this)); | 
 |  |  | 
 |  |  |         adapter = new EditeAdapter(items); | 
 |  |  |         recyclerView.setAdapter(adapter); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     protected void onDestroy() { | 
 |  |  |         super.onDestroy(); | 
 |  |  |         // Save items to SharedPreferences | 
 |  |  |         saveItemsToSharedPreferences(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void saveItemsToSharedPreferences() { | 
 |  |  |         SharedPreferences.Editor editor = sharedPreferences.edit(); | 
 |  |  |         Gson gson = new Gson(); | 
 |  |  |         String json = gson.toJson(items); | 
 |  |  |         editor.putString("items", json); | 
 |  |  |         editor.apply(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private List<Item> loadItemsFromSharedPreferences() { | 
 |  |  |         Gson gson = new Gson(); | 
 |  |  |         String json = sharedPreferences.getString("items", null); | 
 |  |  |         if (json != null) { | 
 |  |  |             Type type = new TypeToken<List<Item>>(){}.getType(); | 
 |  |  |             return gson.fromJson(json, type); | 
 |  |  |         } | 
 |  |  |         return new ArrayList<>(); | 
 |  |  |     } | 
 |  |  | } |