title: How to convert Drawable into int and vice versa in Android
body: <p>I want to convert <strong>Drawable</strong> into <strong>int</strong> and then vice versa.Basically I want to save <strong>Arraylist</strong> object into <strong>sharedPrefrence</strong>. For that purpose I have Implement <strong>Gson</strong> to Srtring convertion Method. If I use here <strong>Drawable</strong> instead of <strong>int</strong> then Gson String convertion take alot of time. so I want to use int instead of Drawable.</p>
  
  <pre><code> private List&lt;AppInfo&gt; apps = null;
  
     public void setIcon(int icon) {
      this.icon = icon;
  }
  
     apps.get(position).setIcon(mContext.getResources().getDrawable(apps.get(position).getIcon()));
  </code></pre>
  
  <p>Where AppInfo here is</p>
  
  <pre><code>    public AppInfo(String appname, String pname, String versionName, int versionCode, int icon, int color) {
      this.appname = appname;
      this.pname = pname;
      this.versionName = versionName;
      this.versionCode = versionCode;
      this.icon = icon;
      this.color = color;
  }
  </code></pre>
  
  <p>Here is source of Converting ArrayList of Custom object into String so that i can save it to SharedPrefrence.</p>
  
  <pre><code>            Gson gson = new Gson();
              apps.get(number).setColor(picker.getColor());
              String JsonAppsdata = gson.toJson(apps);
              System.out.println("Storing="+JsonAppsdata);
              utility.StoreData(getApplicationContext(), JsonAppsdata);
  </code></pre>