Code to set the background image to the relative layout from one activity to another
in the first activity see the code shown below
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
// TODO Auto-generated method stub
if(requestCode == 1011)
{
if(resultCode == RESULT_OK)
{
image.setImageURI(data.getData());
imageUri = data.getData();
String filePath[] = {MediaStore.Images.Media.DATA}; //A column name which to be return
Cursor c = getContentResolver().query(imageUri, filePath, null, null, null);
c.moveToFirst();
int index = c.getColumnIndex(filePath[0]);
String path = c.getString(index);//actual path of file in sa card
c.close();
if(path!=null)
{
//Bitmap bmp =BitmapFactory.decodeFile(path);
SharedPreferences.Editor editor = pref.edit();
editor.putString("image",path);//set the path of file into the SharedResources
editor.commit();
}
}
}
}
code to set background image
void setLayoutBackground()
{
SharedPreferences pref = getSharedPreferences("style_pref", 0);
String path = pref.getString("image",null);
Bitmap myBitmap = BitmapFactory.decodeFile(path);
BitmapDrawable d = new BitmapDrawable(getResources(),myBitmap);
layout.setBackgroundDrawable(d);
}