title: set SharedPreferences name dynamically
body: <p>I'm using this sequence for designing an app:</p>
  
  <p>(This classes will not change and I'm gonna use them for multiple activities)</p>
  
  <ol>
  <li>Custom adapter</li>
  <li>Model Class</li>
  <li>Shared Preferences</li>
  </ol>
  
  <p>And <code>Activity</code> with tab Layouts(with two Fragments) wich contains:</p>
  
  <p>I'm gonna name this: (Package #1)</p>
  
  <ul>
  <li>MainActivity</li>
  <li>Fragment One</li>
  <li>Fragment Two</li>
  </ul>
  
  <p>Now I want to duplicate <em>Package #1</em> and change some contents then name it as Package #2. But I have a problem here.</p>
  
  <p>I'm using one shared preferences for Package #1, Package #2, Package #3..., right?
  please have a look into my shared preferences class:</p>
  
  <pre><code>public class SharedPreference_light {
  
      private SharedPreferences settings;
      private SharedPreferences.Editor editor;
      private Gson gson = new Gson();
  
      private static final String PREFS_NAME = "Light_Products";
      private static final String FAVORITES = "Favorite_Tones_Light";
  
  
  
      public SharedPreference_light(Context context) {
          settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
          editor = settings.edit();
      }
  
      private void saveFavorites(List&lt;ProductLocal&gt; favorites) {
          String jsonFavorites = gson.toJson(favorites);
          editor.putString(FAVORITES, jsonFavorites);
          editor.apply();
      }
  
      public void addFavorite(ProductLocal product) {
          List &lt;ProductLocal&gt; favorites = getFavorites();
          if (favorites == null)
              favorites = new ArrayList&lt;&gt;();
          favorites.add(product);
          saveFavorites(favorites);
      }
  
      public void removeFavorite(ProductLocal product) {
          ArrayList &lt;ProductLocal&gt; favorites = getFavorites();
          if (favorites != null) {
              favorites.remove(product);
              saveFavorites(favorites);
          }
      }
  
      public ArrayList &lt;ProductLocal&gt; getFavorites() {
          List&lt;ProductLocal&gt; favorites;
          if (settings.contains(FAVORITES)) {
              String jsonFavorites = settings.getString(FAVORITES, null);
              ProductLocal[] favoriteItems = gson.fromJson(jsonFavorites, ProductLocal[].class);
              favorites = Arrays.asList(favoriteItems);
              favorites = new ArrayList &lt;&gt; (favorites);
          } else
              return null;
  
          return (ArrayList &lt;ProductLocal&gt; ) favorites;
      }
  }
  </code></pre>
  
  <p>The problem is if I use this two <strong><em>variables</em></strong>:</p>
  
  <pre><code>private static final String PREFS_NAME = "Light_Products";
  private static final String FAVORITES = "Favorite_Tones_Light";
  </code></pre>
  
  <p>There will be a conflict between those packages. because I'm going to add some list items into shared preferences and use <code>getSharedPreferences</code>. then all those items from multiple packages will be added into one shared preferences, and I don't want that. </p>
  
  <p>Now my real question would be:</p>
  
  <p>How can I set shared preferences names(<strong><em>variables</em></strong>) dynamically?</p>
  
  <p><strong>Note:</strong>
  I have one usage of shared preferences in custom adapter:</p>
  
  <pre><code>private boolean checkFavoriteItem(ProductLocal checkProduct) {
      boolean check = false;
      List&lt;ProductLocal&gt; favorites = sharedPreference.getFavorites();
      if (favorites != null) {
          for (ProductLocal product : favorites) {
              if (product.equals(checkProduct)) {
                  check = true;
                  break;
              }
          }
      }
      return check;
  }
  </code></pre>
  
  <p>Adapter:</p>
  
  <pre><code>public class LocalAdapter extends RecyclerView.Adapter&lt;LocalAdapter.MyViewHolder&gt;{
  
  private SharedPreference_light sharedPreference;
  
  
  public LocalAdapter(Activity activity, List&lt;ProductLocal&gt; dataList, RelativeLayout snackLayout) {
      this.snackLayout=snackLayout;
      this.activity = activity;
      this.dataList = dataList ;
      this.dataListFilter = dataList ;
      sharedPreference = new SharedPreference_light(activity);
      methods = new Methods(activity);
  }
  </code></pre>