动作条向上按钮和导航模式按钮、动作、模式

2023-09-12 01:51:27 作者:做朶太阳花,努力微笑

我想实现导航模式的我,在动作条上按钮的应用程序。

I want to implement Navigation Pattern in my app with Up button in ActionBar.

我有详细的活动,在这里我可以来自家庭,收藏夹和搜索屏幕。我也可以从浏览器中打开该屏幕(处理特定URL)。当用户preSS向上按钮,我用flush()方法,模拟后退导航。但对于情况下,当用户来自浏览器,我想打开主屏幕,而不是previous浏览器活动。我怎么能认识,即previous活动是从另外一个应用程序,并导航到主屏幕?

I have Details Activity, here I can come from home, favorites and search screen. Also I can open this screen from browser(handling specific url). When user press Up button, I use flush() method, to emulate back navigation. But for case, when user come from browser, I want to open home screen instead of previous browser activity. How I can recognize, that previous activity was from another app, and navigate to home screen?

推荐答案

行动应始终导航到该活动的层次父母和回应该经常浏览时间。

Up Should always navigate to the hierarchical parent of the activity and Back should always navigate temporally.

在换句话说,你应该请假回原样。

In other words you should leave Back as it is.

至于向上,它应该总是去同一个地方,无论它来自何处。所以,如果你常来的DetailsActivity从YourListActivity,最多要经常去那里,不管你来自哪里。什么是最有可能的地方就是到你的自由裁量权,但它应该始终是相同的。

As for Up, it should always go to the same place no matter where it came from. So if you normally come to the DetailsActivity from YourListActivity, Up should always go there no matter where you came from. What is the most likely place is up to your discretion, but it should always be the same.

如果您从一个非正常的位置,来到了详细的活动(如浏览器,另一个活动,窗口小部件,或通知),你应该这样使用起来导航效果相同路径重新创建任务的堆栈。下面是从Android开发者培训的一个例子:

If you come to the Details Activity from a non-normal location (such as the browser, another activity, widget, or notification) you should recreate your task stack so navigation using up results in the same path. Here is an example from the Android Developer Training:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        Intent upIntent = new Intent(this, YourListActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so
            // create a new task
            // with a synthesized back stack.
            TaskStackBuilder
                    .from(this)
                    .addNextIntent(new Intent(this, HomeActivity.class))
                    .addNextIntent(upIntent).startActivities();
            finish();
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
}

下面是Android培训上实施导航

Here is the Android Training on Implementing Navigation

(http://developer.android.com/training/implementing-navigation/index.html).

您将需要NavUtils和TaskStackBuilder支持库。

You will need the support library for NavUtils and TaskStackBuilder.