Turbolinks Android适配器 - 从哪里开始



非常新的Android开发以及用于Turbolinks的Android适配器5。我编写了一个加载网站的小应用程序,单击链接可以正常工作,但是按下了电话上的后退按钮;返回页面,但没有一个链接可以工作,我不能滑动到刷新。

关于我需要从哪里开始寻找的任何想法将不胜感激。不确定什么甚至有助于引用我已经完成的代码,但认为这是主要位:

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);
        }
    }
}

饰面和退出行不通,我还必须两次回击才能弹出当前的屏幕,但它粗略地工作了,当我需要时,我会完善的(目前只是对概念的测试(。<<<<<<<<<<<<<</p>

稍作搜索之后,这是我用来启动和运行的东西。

@Override
protected void onRestart() {
    super.onRestart();
    TurbolinksSession.getDefault(this)
            .activity(this)
            .adapter(this)
            .restoreWithCachedSnapshot(true)
            .view(turbolinksView)
            .visit(location);
}

我才刚刚开始,所以任何评论/更正都很好。

最新更新