내 앱을 사용하면 앱을 시작할 때마다 기본 화면을 선택할 수 있고 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);
}
}
});
editor.apply()를 호출 해 보았습니까? – Jack
같은 일을 editor.commit()하지 말아야합니까? – tedbrooks2
그래, 문서는 그들이 똑같이한다고, 나는 그 가치가있는 시도를 말하고 있었다 :). – Jack