2017-05-06 29 views
1

非常新的Android開發和Turbolinks的Android適配器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); 
} 

更新 - 意識到這是重寫onBackPressed方法的需要。我有類似:

@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

我有完全相同的問題。你有這個運氣嗎?我使用Bootstrap進行佈局,並想知道這可能是相關的嗎? –

+0

我有。使用上面的訪問回調函數將位置推送到堆棧...然後使用後退按鈕回調我彈出最後一個位置並將其作爲活動啓動。回到辦公室後,我會添加更多細節。 – SimonKiteley

回答

1

經過一番搜索,這是我用來啓動和運行。

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

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

我剛剛開始,所以任何意見/更正會很好。