Implementing Descendant Navigation 实现下一代导航

本文探讨了在不同设备上实现主从导航流程的方法,包括使用Intent在手机上启动新活动以显示详细信息,以及在平板电脑上利用FragmentTransaction进行内容面板的替换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Descendant navigation is navigation down the application's information hierarchy. This is described inDesigning Effective Navigation and also covered in Android Design: Application Structure.

Descendant navigation is usually implemented using Intent objects andstartActivity(), or by adding fragments to an activity usingFragmentTransaction objects.http://blog.youkuaiyun.com/sergeycao

Implement Master/Detail Flows Across Handsets and Tablets

In a master/detail navigation flow, a master screen contains a list of items in a collection, and adetail screen shows detailed information about a specific item within that collection. Implementing navigation from the master screen to the detail screen is one form of descendant navigation.

Handset touchscreens are most suitable for displaying one screen at a time (either the master or the detail screen); this concern is further discussed inPlanning for Multiple Touchscreen Sizes. Descendant navigation in this case is often implemented using anIntent that starts an activity representing the detail screen. On the other hand, tablet displays, especially when viewed in the landscape orientation, are best suited for showing multiple content panes at a time: the master on the left, and the detail to the right). Here, descendant navigation is usually implemented using aFragmentTransaction that adds, removes, or replaces the detail pane with new content.

The basics of implementing this pattern are described in the Implementing Adaptive UI Flows lesson of theDesigning for Multiple Screens class. The class describes how to implement a master/detail flow using two activities on a handset and a single activity on a tablet.

Navigate into External Activities

There are cases where descending into your application's information hierarchy leads to activities from other applications. For example, when viewing the contact details screen for an entry in the phone address book, a child screen detailing recent posts by the contact on a social network may belong to a social networking application.

When launching another application's activity to allow the user to say, compose an email or pick a photo attachment, you generally don't want the user to return to this activity if they relaunch your application from the Launcher (the device home screen). It would be confusing if touching your application icon brought the user to a "compose email" screen.

To prevent this from occurring, simply add the FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET flag to the intent used to launch the external activity, like so:

Intent externalActivityIntent = new Intent(Intent.ACTION_PICK);
externalActivityIntent.setType("image/*");
externalActivityIntent.addFlags(
        Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(externalActivityIntent);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值