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