android - Turbolinks Android 适配器 - 后退按钮从哪里开始

标签 android back turbolinks adaptor

Android 开发和 Turbolinks 5 的 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);
        }
    }
}

完成和退出不起作用,而且我必须回击两次才能弹出当前屏幕,但它大致可以工作,我会在需要时进行改进(目前只是概念测试)。

最佳答案

经过一番搜索后,这就是我用来启动和运行的。

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

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

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

关于android - Turbolinks Android 适配器 - 后退按钮从哪里开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43826122/

相关文章:

java - 媒体播放器和服务类

android - 如何让 'cordova run --release'使用签名的apk

Android Studio 出现奇怪的 "cascading display"故障?

android - 按下后退按钮时亮度不会保存

android - 如何转到 Android Studio 中的上次编辑位置

android - 是否可以将 kotlin 中的高阶函数映射到字符串

javascript - 使用 BACK 按钮恢复到页面的先前状态

ios - 在 Web App 和 IOS App 之间持久化用户

jquery - 页面更改后,rails jquery.turbolinks javascript 未触发

javascript - Rails 4 Turbolinks 未加载 MathJax