2012-11-24 3 views
2

공유 환경 설정 관련 문제가 있습니다. 예상대로 작동하지 않습니다. 응용 프로그램에 로그인하면 공유 환경 설정에 ID (Google ID)가 저장됩니다. 후속 활동 (약 3 활동 후)에서 ID를 검색하려고 시도했지만 null입니다. 중요한 경우, 버튼에서 onClickListener의 공유 환경 설정을 검색하려고 시도하고 있습니다. 내가 뭘 잘못하고 있는지 모르겠다. 어떤 도움을 주시면 감사하겠습니다.SharedPreferences가 예상대로 작동하지 않습니다.

것은 나는 그것을 설정하고 방법 :

public void setLoginPreferences(String id){ 

    SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit(); 
    editor.putString(Constants.ID_KEY_NAME, id); 
    editor.commit(); 
} 

어떻게 그걸 얻기 위해 시도하고있다 :

//setup clickListener for Sumbit Comment 
    Button submitButton = (Button) findViewById(R.id.submitComment); 
    submitButton.setOnClickListener(new OnClickListener(){ 

     @Override 
     public void onClick(View v) { 
      //myContext is a global variable set on the onCreate of the activity 
      SharedPreferences prefs = myContext.getPreferences(MODE_PRIVATE); 
      String userId = prefs.getString(Constants.ID_KEY_NAME, null); 
      SetConcertCommentAsynchWebservice scca = new SetConcertCommentAsynchWebservice(myContext,concertId,userId,Float.toString(soundRatingBar.getRating()),Float.toString(showRatingBar.getRating()),userSubmittedComments.getText().toString()); 
     }}); 
} 

답변

3

당신이 context.getPreferences() 대신 context.getSharedPreferences()을 사용할 수 있습니다, 당신은 다른 곳에서 그들에 액세스하려면 .

+0

그게 전부 였어! 고맙습니다. – mornindew

관련 문제