博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Implementing Ancestral Navigation 实现原始导航
阅读量:4046 次
发布时间:2019-05-24

本文共 3370 字,大约阅读时间需要 11 分钟。

Ancestral navigation is up the application's information hierarchy, where the top of the hierarchy (or root) is the application's home screen. This navigation concept is described in . http://blog.csdn.net/sergeycao

Implement Up Navigation

When implementing ancestral navigation, all screens in your application that aren't the home screen should offer a means of navigating to the immediate parent screen in the hierarchy via the Up button in the action bar.

Regardless of how the current screen was reached, pressing this button should always take the user to the same screen in the hierarchy.

To implement Up, enable it in the action bar in your activity's method:

@Overridepublic void onCreate(Bundle savedInstanceState) {    ...    getActionBar().setDisplayHomeAsUpEnabled(true);    ...}

You should also handle android.R.id.home in . This resource is the menu item ID for the Home (or Up) button. To ensure that a specific parent activity is shown, DO NOT simply call . Instead, use an intent such as the one described below.

@Overridepublic boolean onOptionsItemSelected(MenuItem item) {    switch (item.getItemId()) {        case android.R.id.home:            // This is called when the Home (Up) button is pressed            // in the Action Bar.            Intent parentActivityIntent = new Intent(this, MyParentActivity.class);            parentActivityIntent.addFlags(                    Intent.FLAG_ACTIVITY_CLEAR_TOP |                    Intent.FLAG_ACTIVITY_NEW_TASK);            startActivity(parentActivityIntent);            finish();            return true;    }    return super.onOptionsItemSelected(item);}

When the current activity belongs to a task from a different application—for example if it was reached via an intent from another application—pressing Up should create a new task for the application with a synthesized back stack. This approach is described in and the class reference.

The and classes in the provide helpers for implementing this behavior correctly. An example usage of these two helper classes is below:

@Overridepublic boolean onOptionsItemSelected(MenuItem item) {    switch (item.getItemId()) {        case android.R.id.home:            Intent upIntent = new Intent(this, MyParentActivity.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, MyGreatGrandParentActivity.class))                        .addNextIntent(new Intent(this, MyGrandParentActivity.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;    }    return super.onOptionsItemSelected(item);}

Properly Handle the Application Home Screen

By default, the Home button in the action bar is interactive. Since it does not make much sense to navigate home—or up one level—while on the home screen, you should disable the button like so:

getActionBar().setHomeButtonEnabled(false);
你可能感兴趣的文章
Yotta企业云盘更好的为媒体广告业服务
查看>>
Yotta企业云盘助力旅游行业新发展
查看>>
Yotta企业云盘助力科技行业创高峰
查看>>
Yotta企业云盘更好地为教育行业服务
查看>>
Yotta企业云盘怎么帮助到能源化工行业
查看>>
企业云盘如何助力商业新发展
查看>>
医疗行业运用企业云盘可以带来什么样的提升
查看>>
教育数字智能化能为现有体系带来新的起点
查看>>
媒体广告业如何将内容资产进行高效地综合管理与利用
查看>>
能源化工要怎么管控核心数据
查看>>
媒体广告业如何运用云盘提升效率
查看>>
企业如何运用企业云盘进行数字化转型-实现新发展
查看>>
司法如何运用电子智能化加快现代化建设
查看>>
设计行业运用企业云盘能带来什么样的变化
查看>>
iSecret 1.1 正在审核中
查看>>
IOS开发的开源库
查看>>
IOS开发的开源库
查看>>
SonarQube 7.8 启动后又关闭,其他失败总结
查看>>
jenkins 构建细节 - 邮件通知
查看>>
Jenkins - sonarqube 代码审查
查看>>