在Android的覆盖活动/任务的行为 [英] Overriding the Activity/Task behavior in Android

查看:182
本文介绍了在Android的覆盖活动/任务的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个简单的Andr​​oid应用程序,我想更好地控制活动之间的导航/关系。我不希望我的活动,像Android的活动......我不希望他们的任务范围内叠起来。我想要一个活动(姑且称之为 MainActivity )为着陆点,并始终位于堆栈底部,我想只有一个我的第二个活动实例(称之为 SecondActivity )是它上面的堆栈......将是很好的重用它。我以为我可以通过获得这种行为的 MainActivity 是主活动,并宣布他们既作为 launchMode = singleTop 。这是行不通的。我提供导航它们之间通过菜单来使用,所以当我来回走了一堆的时间,背出的应用程序,我经历了整个堆栈。

I'm writing a simple Android app, and I'd like better control over the navigation/relationship between the activities. I don't want my activities to act like android activities...I don't want them to stack up within the Task. I want one Activity (let's call it MainActivity) to be the landing point and always be at the bottom of the stack, and I want only one instance of my second activity (call it SecondActivity) to be above it in the stack...would be nice to reuse it as well. I thought I could get this behavior by making MainActivity be the "main" Activity, and declare them both as launchMode=singleTop. This isn't working at all. I provide navigation between them using menus, so when I go back and forth a bunch of times and back out of the app, I go through the whole stack.

怎么样有良好的控制任务的活动的最佳方式栈?我想 MainActivity 总是背出该应用程序的,和 SecondActivity 总是回MainActivity的一个实例。同时,我很想得到singleTop工作,所以我会用 onNewIntent 而不是创建和销毁每次。使用清单以及意图标志只是不工作。任何想法?

How's the best way to have fine control over the Task's Activity stack? I want MainActivity to always back out of the app, and SecondActivity to always back into a single instance of MainActivity. As well, I'd love to get singleTop working so I would use onNewIntent instead of creating and destroying every time. Using the manifest as well as the intent flag is just not working. Any ideas?

推荐答案

嗯,你总是可以只需要调用完成()内的任何活动是调用startActivity()调用之后另一项活动。我肯定会建议不要试图东西整个应用程序分成两个活动课,并尝试交换基础上,他们正在做的事情的看法。如果这是对你很重要,只要闭上你的活动,你推出新的(显然不是MainActivity,虽然)。

Well, you could always just call "finish()" within whatever Activity is calling another activity after the "startActivity()" call. I would definitely advise against trying to stuff an entire app into two activity classes and try to swap views based on what they're doing. If it's that important to you, just close your activities as you launch new ones (obviously not the MainActivity, though).

这篇关于在Android的覆盖活动/任务的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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