2013-08-14 2 views
0

활동의 인스턴스 상태 저장 및 복원이 완전히 중단되었습니다. 여기에 내가 무엇을 가지고 : 나는 "라고 SAVE"의 출력을 얻고있다Android : 인스턴스 상태 저장/복원

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_register1); 

    context = this; 

    input_first_name = (EditText) findViewById(R.id.first_name); 
    input_last_name = (EditText) findViewById(R.id.last_name); 
    input_email = (EditText) findViewById(R.id.register_email); 
    input_password = (EditText) findViewById(R.id.register_password); 
    input_cell = (EditText) findViewById(R.id.register_cell); 

    if (savedInstanceState != null) { 
     System.err.println(savedInstanceState.getString("first_name")); 
     input_first_name.setText(savedInstanceState.getString("first_name")); 
     input_last_name.setText(savedInstanceState.getString("last_name")); 
     input_email.setText(savedInstanceState.getString("email")); 
     input_password.setText(savedInstanceState.getString("password")); 
     input_cell.setText(savedInstanceState.getString("cell")); 
    } 
    ... 
} 

protected void onSaveInstanceState(Bundle b) { 
    super.onSaveInstanceState(b); 
    System.err.println("save called"); 

    b.putString("first_name", first_name); 
    b.putString("last_name", last_name); 
    b.putString("email", email); 
    b.putString("password", password); 
    b.putString("cell", cell); 
} 

protected void onRestoreInstanceState(Bundle b) { 
    System.err.println(b.getString("first_name")); 
    input_first_name.setText(b.getString("first_name")); 
    input_last_name.setText(b.getString("last_name")); 
    input_email.setText(b.getString("email")); 
    input_password.setText(b.getString("password")); 
    input_cell.setText(b.getString("cell")); 
} 

, 그래서 난 내 번들이 올바르게 저장되었다고 생각합니다. 그러나 나는 다시 활동으로 돌아 왔을 때 어떤 결과물도 보지 못했다. 누구든지 내가 뭘 잘못하고 있는지 알아? 감사!

@Override 
protected void onSaveInstanceState(Bundle b) { 
super.onSaveInstanceState(b); 
System.err.println("save called"); 

b.putString("first_name", first_name); 
b.putString("last_name", last_name); 
b.putString("email", email); 
b.putString("password", password); 
b.putString("cell", cell); 
} 
+1

우선, 기본값 (saveState.getString ("abc", "default"))을 지정하는보다 안전한 "get"메소드를 사용해야합니다. – samosaris

+1

변수의 값 (first_name, ...)을 어디에도 설정하지 않습니다. –

+0

'onRestoreInstanceState' 메소드는 액티비티가 다시 생성 될 때만 호출됩니다. 어떻게 활동을 모방 하는가? – nfirex

답변

0

확실히 그것은 그 함수

처럼 다음과 슈퍼 클래스의 하나의 클래스에서가 아니라 호출 onRestoreInstanceState을 올바르게 사용했는지 확인하십시오.

+0

좋은 아이디어. 불행히도 일하지 않았습니다. – Alex

+0

@ usr55410 아직 문제를 해결하지 않았다면 빈을 붙여서 코드를 더 많이 보여줄 수 있습니까? www.pastebin.com – Br0thazS0ul

0

this solution을보십시오 : 정말 일이 잘못 할 @Override 추가를 참조하지 않는