首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >管理android的后台

管理android的后台
EN

Stack Overflow用户
提问于 2015-11-23 20:07:38
回答 2查看 71关注 0票数 4

我有一个活动层次结构,我有一个按钮,允许我从活动D转到活动B。

问题是,从D到B会把C留在后台,所以如果我做A->C->D->B,然后按后退,它会把我发送到C,而不是A(这就是我想要的)。

当我点击B中的按钮时,是否有一种删除C的方法,还是有某种解决办法?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-11-24 09:57:43

考虑使用A作为调度器。当您希望从B启动D并在此过程中完成C时,请使用D执行此操作

代码语言:javascript
运行
复制
// Launch A (our dispatcher)
Intent intent = new Intent(this, A.class);
// Setting CLEAR_TOP ensures that all other activities on top of A will be finished
//  and setting SINGLE_TOP ensures that a new instance of A will not
//  be created (the existing instance will be reused and onNewIntent() will be called)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
// Add an extra telling A that it should launch B
intent.putExtra("startB", true);
startActivity(intent);

A.onNewIntent()中这样做:

代码语言:javascript
运行
复制
@Override
protected void onNewIntent(Intent intent) {
    if (intent.hasExtra("startB")) {
        // Need to start B from here
        startActivity(new Intent(this, B.class));
    }
}
票数 1
EN

Stack Overflow用户

发布于 2015-11-23 21:06:58

我不知道调用B、C和D的具体方式,也不知道数据是如何传递的,但如果需要,可以在调用D时关闭C。

在C中,当启动D时,您可以这样做:

代码语言:javascript
运行
复制
Intent intent = new Intent(this, D.class);
startActivity(intent);
finish();

结束将在开始D之后关闭C。

再一次,没有太多的信息,这只是一个在黑暗中拍摄。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33879719

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档