2017-05-06 11 views
1

Android 개발 및 Android 용 Turbolinks 5의 새로운 기능입니다. 5. 웹 사이트를로드하는 작은 응용 프로그램을 작성 했으므로 링크를 클릭해도 작동하지만 확인을 누릅니다. 페이지를 다시 탐색하지만 링크가 작동하지 않으며 아래로 스 와이프하여 새로 고침 할 수 없습니다.Turbolinks Android 어댑터 - 뒤로 버튼

내가 어디에서 시작해야하는지에 대한 아이디어는 인정 될 것입니다. 이미 수행하지만 한 코드의 인용에도 도움이 무엇인지 확실하지 않음이 메인 비트 생각 :

public static Stack<String> intent_history = new Stack<String>(); 

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    // Find the custom TurbolinksView object in your layout 
    turbolinksView = (TurbolinksView) findViewById(R.id.turbolinks_view); 

    // For this demo app, we force debug logging on. You will only want to do 
    // this for debug builds of your app (it is off by default) 
    TurbolinksSession.getDefault(this).setDebugLoggingEnabled(true); 

    // For this example we set a default location, unless one is passed in through an intent 
    location = getIntent().getStringExtra(INTENT_URL) != null ? getIntent().getStringExtra(INTENT_URL) : BASE_URL; 

    // Execute the visit 
    TurbolinksSession.getDefault(this) 
      .activity(this) 
      .adapter(this) 
      .view(turbolinksView) 
      .visit(location); 
} 


public void visitProposedToLocationWithAction(String location, String action) { 
    Intent intent = new Intent(this, MainActivity.class); 
    intent.putExtra(INTENT_URL, location); 

    intent_history.push(location); // Added to support UPDATE below 

    this.startActivity(intent); 
} 

UPDATE가 -가 onBackPressed 메소드를 오버라이드 (override) 할 필요가 있었다 실현. 내가 좋아하는 뭔가를 :

@Override 
public void onBackPressed() { 

     if (intent_history.isEmpty()) { 
      finish(); 
      System.exit(0); 
     } 
     else { 
      Intent intent = new Intent(this, MainActivity.class); 
      intent.putExtra(INTENT_URL, intent_history.pop()); 

      this.startActivity(intent); 
     } 
    } 
} 
는 현재 화면을 팝업하지만 대략 작품과 내가 (단지에 필요로 할 때 내가 수정 할 수 있도록

마무리 종료가 작동하지 않고 또한 내가 두 번 다시 쳐야 현재 개념 테스트).

+0

정확히 같은 문제가 있습니다. 이걸 가지고 행운이 있니? 내 레이아웃에 부트 스트랩을 사용하고 있는데 이것이 관련 될 수 있는지 궁금해하고 있었습니까? –

+0

있습니다. 위의 방문 콜백을 사용하여 위치를 스택에 푸시했습니다. 그런 다음 뒤로 버튼 콜백을 사용하여 마지막 위치를 팝하고 활동으로 시작합니다. 사무실에있을 때 자세한 내용을 추가하겠습니다. – SimonKiteley

답변

1

약간의 검색 후 이것이 내가 일어나서 실행하는 데 사용하고있는 것입니다.

@Override 
protected void onRestart() { 
    super.onRestart(); 

    TurbolinksSession.getDefault(this) 
      .activity(this) 
      .adapter(this) 
      .restoreWithCachedSnapshot(true) 
      .view(turbolinksView) 
      .visit(location); 
} 

저는 시작하기 만하면 어떤 의견이나 수정 사항도 좋을 것 같습니다.