2

내 사용자 정의보기에서 복원하지 않을 경우 새 인스턴스를 복원하거나 만들려는 필드가 있습니다. 놀랍게도 내가보기가 복원됩니다 여부를 확인 할 수 있습니다 사용자 정의보기 내부의 체크가 있다고뷰 상태 복원 여부를 결정하는 방법

Examle 클래스

class MyView extends View { 
    private Calendar calendar; 
    public MyView(Context context) { 
     super(context); 
     if(!restoring()) 
      calendar = Calendar.getInstance(); 
    } 

    @Nullable 
    @Override 
    protected Parcelable onSaveInstanceState() { 
     Bundle b = new Bundle(); 
     b.putParcelable("state", super.onSaveInstanceState()); 
     b.putLong("calendar", calendar.getTimeInMillis()); 
     return b; 
    } 

    @Override 
    protected void onRestoreInstanceState(Parcelable state) { 
     if (state instanceof Bundle) { 
      Bundle b = ((Bundle) state); 
      super.onRestoreInstanceState(b.getParcelable("state")); 
      calendar = Calendar.getInstance(); 
      calendar.setTimeInMillis(b.getLong("calendar")); 
     } 
    } 
} 

에 대한 답변을 찾지 못 하셨나요? Activity에서

Bundle savedInstanceState 내가 정적 부울을 생각 onCreate()

에 전달하지만 갈 방법이 아니다 있습니다.

답변

2

보기를 복원할지 여부를 결정할 수있는 사용자 정의보기 안에 몇 가지 검사가 있습니까?

View 클래스 내 는 이러한 API를 존재하지가 않습니다.

을 주어진 유일한 심 "null 상태로 호출되지 않을"것 onRestoreInstanceState(Parcelable)입니다. 따라서, 만약 당신이 onRestoreInstanceState()에있게된다면, 당신은 그 전망이 복원되고 있다고 가정 할 수 있습니다. 그렇지 않으면 이 아니라입니다.

+0

내 논리를 재구성해야하기 때문에 불행합니다. 설명 주셔서 감사합니다. – Tuby

관련 문제