【问题标题】:Turbolinks Android Adaptor - back button where to startTurbolinks Android Adapter - 后退按钮从哪里开始
【发布时间】:2017-05-06 22:54:02
【问题描述】:

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

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

【问题讨论】:

  • 我遇到了完全相同的问题。你有这方面的运气吗?我正在使用 Bootstrap 进行布局,想知道这是否相关?
  • 我有。使用上面的访问回调,我将位置推送到堆栈......然后使用后退按钮回调,我弹出最后一个位置并将其作为活动启动。回到办公室后,我会添加更多详细信息。

标签: android back turbolinks adaptor


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多