Android的Activity.getParent()总是返回null [英] Android Activity.getParent() always returning null
问题描述
我在这里有这个小功能:
I have this little function here:
public Activity getRootActivity()
{
Activity a = this;
while (a.getParent() != null)
a = a.getParent();
return a;
}
但a.getParent()始终返回null。它似乎并不无论我怎样深入到我的UI去,它总是会返回null。
But a.getParent() always returns null. It doesn't seem to matter how deep into my UI I go, it will always return null.
任何人有任何想法,为什么?
Anybody have any idea as to why?
修改
下面是我如何我开始活动(在其他活动)
Here is how I am starting Activities (within other activities)
startActivity(new Intent(this, activityname.class));
显然,这意味着我不是'嵌入'呢?一个人如何嵌入他们?
Apparently that means I'm not 'embedding' them? How does one 'embed' them?
推荐答案
文件说:公共最后活动的getParent()
自:API等级1
Documentation says: public final Activity getParent () Since: API Level 1
返回父活动,如果这种观点是一个嵌入式的孩子。
Return the parent activity if this view is an embedded child.
是您的活动嵌入的孩子?
Is your Activity an embedded child?
这篇关于Android的Activity.getParent()总是返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!