2011-10-22 2 views
0

내 앱을 사용하면 앱을 시작할 때마다 기본 화면을 선택할 수 있고 SharedPreferences를 사용하여 사용자가 기본 화면을 선택할 수 있습니다. 응용 프로그램은 설치 후 처음 실행될 때 화면을 선택하라는 메시지를 표시하고 해당 부분이 작동합니다. 그러나 사용자가 기본 화면을 변경할 수있는 앱 내부에서 동일한 코드를 사용하며 변경 사항을 저장하지 않습니다. 제대로 저장하려면 무엇을 변경해야합니까?사용자가 기본 화면을 변경하도록 허용

myPrefs = PreferenceManager.getDefaultSharedPreferences(ScreenSaverActivity.this); 

난 당신이 한 방법이 작동하지 않을 것을 확실히 모르겠지만, : 공유 환경 설정에 대한 참조를 얻기 위해 같은 것을 사용

  AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setTitle("Choose a Default Screen"); 
     builder.setItems(R.array.openChoices, new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int item) { 
       SharedPreferences settings = getPreferences(0); 
       SharedPreferences.Editor editor = settings.edit(); 
       editor.putInt("start", item); 
       editor.commit(); 
       //Mech = 0, E&M = 1 
       int choice = getPreferences(0).getInt("start", 3); 
       if(choice == 0){ 
        Toast.makeText(setscreen.this, "Mechanics is now the default screen", Toast.LENGTH_SHORT).show(); 
        Intent myIntent = new Intent(setscreen.this, physics.class); 
        startActivity(myIntent);    
       } 
       else if(choice == 1){ 
        Toast.makeText(setscreen.this, "E&M is now the default screen", Toast.LENGTH_SHORT).show(); 
        Intent myIntent = new Intent(setscreen.this, physicsem.class); 
        startActivity(myIntent); 
       } 
      } 
     }); 
+0

editor.apply()를 호출 해 보았습니까? – Jack

+0

같은 일을 editor.commit()하지 말아야합니까? – tedbrooks2

+0

그래, 문서는 그들이 똑같이한다고, 나는 그 가치가있는 시도를 말하고 있었다 :). – Jack

답변

0

봅니다 객체 나는 단지 0을 통과하는 그런 식으로 보지 못했습니다.

+0

좋아,이 사진을 찍어서 어떻게 작동하는지 살펴 보겠습니다. 감사 – tedbrooks2

0

그리고 매번 editor.commit();을 부를 것입니다.

관련 문제