Android Activity.getParent() always returning null

匿名 (未验证) 提交于 2019-12-03 00:46:02

问题:

I have this little function here:

public Activity getRootActivity() {     Activity a = this;     while (a.getParent() != null)         a = a.getParent();     return a; } 

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?

EDIT

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?

回答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?



回答2:

Activity#getParent():

Return the parent activity if this view is an embedded child.

Is the activity an embedded child? If not, getParent() will return null.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!