title: Set background from gallery to all activity background
body: <p>Here's what I'm trying to do.
  I wanted the user to choose a picture from their gallery as set it as every activity background in the application.</p>
  
  <p>Here's what I did
  1.I have a Shared Preference and two other attributes in every activity that I want to apply the wallpaper user choose. Here is the </p>
  
  <pre><code>    private static final String PREF_NAME = "nextage_quiz";
      private static final int PRIVATE_MODE = 0;
      SharedPreferences getPrefs;
  </code></pre>
  
  <p>2.The action take place in settings activity where when the user clicks on the ImageView, it will launch the Gallery Image Selector. Here's the code for the ImageView, the method to start the Gallery Image Selector.</p>
  
  <p>1.Inside the ImageView ClickListener</p>
  
  <pre><code>    private static int Load_Image_From_Gallery = 1;
      Intent i = new Intent(
                      Intent.ACTION_PICK,
                      android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  
              startActivityForResult(i, Load_Image_From_Gallery);
  </code></pre>
  
  <p>2.The onActivityResult Code</p>
  
  <pre><code>    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      if (requestCode == Load_Image_From_Gallery &amp;&amp; resultCode == RESULT_OK &amp;&amp; null != data) {
          Uri selectedImage = data.getData();
          String[] filePathColumn = { MediaStore.Images.Media.DATA };
  
          Cursor cursor = getContentResolver().query(selectedImage,
                  filePathColumn, null, null, null);
          cursor.moveToFirst();
  
          int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
          String picturePath = cursor.getString(columnIndex);
          cursor.close();
  
          ImageViewBackground5.setImageBitmap(BitmapFactory.decodeFile(picturePath));
  
      }
  }
  </code></pre>
  
  <p>As you can see I manage to set the selected image from the gallery as the ImageView background. But I wanted the same image that the user selected to be the background for all the other activity. I have few selection of image in my app to let the user to use it as their background. Here's how I did it.</p>
  
  <ol>
  <li><p>In SettingsActivity (onCreate)</p>
  
  <pre><code>getPrefs = this.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
  </code></pre></li>
  </ol>
  
  <p>Then when the user click on any of the selected image, then the picture is selected as the wallpaper for every activity.</p>
  
  <p>2.Inside the particular imageView</p>
  
  <pre><code>    getPrefs.edit().putInt("id", R.drawable.wallpaper2).apply();
  </code></pre>
  
  <p>3.The code which is placed in all the activity to change the wallpaper.</p>
  
  <pre><code>    getPrefs = this.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
  
      ImageView background= (ImageView) findViewById(R.id.background);
      if(getPrefs.getInt("id",0) != 0) 
         background.setBackgroundResource(getPrefs.getInt("id",0));
  </code></pre>
  
  <p>So again, how can I use the image user selected as the background for every activity. I've tried converting from BitMap to Drawable but still fails.
  Any help would help.
  p.s Most of the codes are from multiple websites. Thanks in Advance.</p>