安卓:通过同一意图发起多个活动实例。带一个独特的到前台? [英] Android: Multiple activity instances launched by same intent. Bring one uniquely to foreground?

查看:175
本文介绍了安卓:通过同一意图发起多个活动实例。带一个独特的到前台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我挣扎与我的应用程序,启动的多个实例 使用相同的意图相同的活动。我的主要活动是类类型 A和它的两个孩子的startActivity()是相同的 类B型。因此,我们有B1和B2推出。如果B1和B2都是 暂停(按下后退按钮,并确保完成()不会被调用 对他们,所以他们是真正的暂停),如何能带来独特的或者B1 或B2再次前景?我也想推出一个新的B活性。一世 要独特的带B1或B2到前台。

I'm struggling with my app that launches multiple instances of the same Activity using the same intent. My main activity is of class type A and it does a startActivity() of two children that are of the same class type B. So we have B1 and B2 launched. If B1 and B2 are both paused (by pushing back button and making sure finish() is not invoked on them so they are truly paused), how can A uniquely bring either B1 or B2 to the foreground again? I do want to launch a new B activity. I want to uniquely bring B1 or B2 to the foreground.

所以B1和B2分别是这样创造了... 意向意图=新的意图(背景下,B.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(意向);

so both B1 and B2 were created like this... Intent intent = new Intent(context, B.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);

现在我要的是把B1(或B2)到前台/前面,所以我用了 低于code,但我怎么开始的时候区分B1或B2 活动?这不仅带来了B的是在顶到最后一个实例 前台。

Now I want A to bring B1 (or B2) to the foreground/front so I use the below code, but how do I distinguish B1 or B2 when starting the activity? This only brings the last instance of B that was on top to the foreground.

意向意图=新的意图(背景下,B.class); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(意向);

Intent intent = new Intent(context, B.class); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(intent);

我试着保持周围引用B1和B2和做的事情 像这样的,但是这也只到活动的最后一个实例 B类,这是在上面......

I've tried keeping around references to B1 and B2 and doing something like this, but this also only goes to the last instance of activity class B that was on top...

意向意图=新的意图(B1context,B.class); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); B1context.startActivity(意向);

Intent intent = new Intent(B1context, B.class); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); B1context.startActivity(intent);

我甚至想这一点,但它仍然犯规把我的独特的B1或B2 ... 意向意图= B1.getIntent(); //即原来的意图 我开始 startActivity(意向); //仍然只能带来正面的最后一个B中 是在顶

I even tried this, but it still doesnt get me my unique B1 or B2... Intent intent = B1.getIntent(); // i.e. the original intent that started me startActivity(intent); // still only brings to front the last B that was on top.

在此先感谢!

推荐答案

感谢。这些都是很好的建议。我曾经考虑过做一个C扩展B.在我的应用程序,我想要做的东西很一般,因为我有乙实例的n个。它不是一个定数。我正在考虑可能在AndroidManifest.xml这些简单的子类的10-20,然后管理他们,因为他们被摧毁,所以我可以重复使用他们。

Thanks. Those are both good suggestions. I had considered making a C that extends B. In my app, I wanted to do things very generically since I have n number of B instances. Its not a set number. I was considering making maybe 10-20 of those simple subclasses in the AndroidManifest.xml and then managing them as they get destroyed so I could reuse them.

我不知道,但看起来类似于子类的想法。最好有另一种选择思考的问题。

I didnt know about but looks similar to the subclass idea. Good to have another option to think about.

这似乎很奇怪,我认为它在Android中并不明显如何处理历史堆栈不是诉诸花样更容易。一切都在那里,除了唯一的ID在堆栈中的活动。

It seems very strange to me that its not obvious in Android how to deal with the history stack easier than resorting to tricks. Everything is all there except to uniquely id an Activity in the stack.

这篇关于安卓:通过同一意图发起多个活动实例。带一个独特的到前台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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