배경화면 변경 페이지를 만들고 있습니다.

 

버튼을 만들어서 버튼을 클릭할 시 해당 액티비티의 배경까지는 바뀌게 했습니다.

 

 public void onClick(View v) {
  // TODO Auto-generated method stub
  if (v.getId() == R.id.bg1) {
   backgroundsettingpage.setBackgroundResource(R.drawable.bg1);

  } else if (v.getId() == R.id.bg2) {
   backgroundsettingpage.setBackgroundResource(R.drawable.bg2); // 버튼을 누르면 배경화면 변경 됨.
   
  } else if (v.getId() == R.id.bg3) {
//   backgroundsettingpage.setBackgroundResource(R.drawable.bg3);
   int bg3 = getResources().getIdentifier("bg3", "drawable", "dongyangmirae.mobile.one");
   backgroundsettingpage.setBackgroundResource(bg3);
  }

 

이런식으로 백그라운드 이미지를 바꾸게는 됐는데요.

 

뒤로가기를 누르고 돌아오면 페이지가 그대로입니다.

 

그리고 다른 액티비티의 백그라운드 이미지도 바뀌게 하고 싶습니다.

 

그래서 검색하던 중 SharedPreferences 를 사용하면 액티비티의 상태를 저장할 수 있다고 나오더라구요.

 

  } else if (v.getId() == R.id.bg4) {
   backgroundsettingpage.setBackgroundResource(R.drawable.bg4);
   
  } else if (v.getId() == R.id.bg5) {
   backgroundsettingpage.setBackgroundResource(R.drawable.bg5);
   
  } else if (v.getId() == R.id.bg6) {
   backgroundsettingpage.setBackgroundResource(R.drawable.bg6);
        
   SharedPreferences pref = getSharedPreferences("pref", Activity.MODE_PRIVATE); // UI 상태를 저장합니다.   
   SharedPreferences.Editor editor = pref.edit();
   // 저장할 값들을 입력합니다.
   editor.putInt("bg6", 6);
   editor.commit();

 

그래서 생각한 것이 버튼을 클릭했을 때 어떤 값을 SharedPreferences로 저장해주어서

 

onCreate가 실행될 때 SharedPreferences 를 불러와서 값에 맞는 백그라운드로 바꿔주려고 합니다.

 

어떻게 불러와야 될지도 잘 모르겠고, 어떻게 저장해야 될지도 잘 모르겠습니다...

----------------------------------------------------------------------------------------------------------------------------

 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
  setContentView(R.layout.backgroundsettingpage);
     // TODO Auto-generated method stub 

 ///////제 생각으론 여기서 불러와서 a라는것에 저장해서 값대로 배경을 바꿔주는건대요..

제가 생각하는 것이 맞는지도 잘 모르겠네요..

 

if(a==1){
   backgroundsettingpage = (RelativeLayout)findViewById(R.id.backgroundsettingpage);
   int bgbg1 = getResources().getIdentifier("bg1", "drawable", "dongyangmirae.mobile.one");
   backgroundsettingpage.setBackgroundResource(bgbg1);
  }else if(a==2){
   backgroundsettingpage = (RelativeLayout)findViewById(R.id.backgroundsettingpage);
   int bgbg2 = getResources().getIdentifier("bg2", "drawable", "dongyangmirae.mobile.one");
   backgroundsettingpage.setBackgroundResource(bgbg2); 
  }else if(a==3){
   backgroundsettingpage = (RelativeLayout)findViewById(R.id.backgroundsettingpage);
   int bgbg3 = getResources().getIdentifier("bg3", "drawable", "dongyangmirae.mobile.one");
   backgroundsettingpage.setBackgroundResource(bgbg3); 
  }else if(a==4){
   backgroundsettingpage = (RelativeLayout)findViewById(R.id.backgroundsettingpage);
   int bgbg4 = getResources().getIdentifier("bg4", "drawable", "dongyangmirae.mobile.one");
   backgroundsettingpage.setBackgroundResource(bgbg4); 
  }else if(a==5){
   backgroundsettingpage = (RelativeLayout)findViewById(R.id.backgroundsettingpage);
   int bgbg5 = getResources().getIdentifier("bg5", "drawable", "dongyangmirae.mobile.one");
   backgroundsettingpage.setBackgroundResource(bgbg5); 
  }else if(a==6){
   backgroundsettingpage = (RelativeLayout)findViewById(R.id.backgroundsettingpage);
   int bgbg6 = getResources().getIdentifier("bg6", "drawable", "dongyangmirae.mobile.one");
   backgroundsettingpage.setBackgroundResource(bgbg6); 
  }

}

그리고... OnCreate 만 썼었는데...

 

onStop, onResume, onPause 등은 액티비티가 사라진다거나, 다시 생성된다거나 할 때 알아서 시작되는건가요..

 

모르는게 너무 많은데 독학으로 배우려고 하니까 힘든 것 같습니다...