The getParent()
function returns a meaningful value when the activity is in a relationship in which it is a child's parent activity. As you explained, if you simply call Activity B from Activity A using Intent, always return null.
A common way to build a parent/child relationship is to use ActivityGroup, which API was defined by Honeycomb. Before the concept of fragment came out, I think it is the remnant of API to use activities like fragments.
If you ask the question again, you need to find out why getParent()
is needed. If it is intended to access Activity A, we usually use the method of passing the data needed to run Activity B to putExtra()
of the int. Please refer to the link below for the code.
© 2024 OneMinuteCode. All rights reserved.