如何控制Android回栈 [英] How to Control Android back stack

查看:24
本文介绍了如何控制Android回栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有

A->B->C->D->E

在 android 后台堆栈中.我希望能够回到以下其中一项:

A->B->CA->B一个

我怎样才能做到这一点?希望不要强迫点击返回按钮.

解决方案

使用Android官方开发者页面的图片和信息:

<块引用>

考虑一个由以下活动组成的任务:A、B、C、D.如果 D 调用startActivity() 的 Intent 解析为活动B,然后C和D将完成,B收到给定的意图,导致堆栈现在是:A,B.

Lets say I have

A->B->C->D->E

In android back stack. I want to be able to get back to one of the following:

A->B->C
A->B
A

How can I achieve this? Hopefully without forcing back button clicks.

解决方案

Using the image and information from the official developers page on Android tasks and back stack you can see that of all other ways to launch an Activity you can ensure such behavior only using the FLAG_ACTIVITY_CLEAR_TOP in your Intent flags.

Your regular back button proceeds as:

But when you specify this flag, you get a behavior like you need, as given by an example at this source:

consider a task consisting of the activities: A, B, C, D. If D calls startActivity() with an Intent that resolves to the component of activity B, then C and D will be finished and B receive the given Intent, resulting in the stack now being: A, B.

这篇关于如何控制Android回栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆