Null when calling getParent() in Activity class?

Asked 2 years ago, Updated 2 years ago, 104 views

Activity A calls Activity B through int and B appears on the screen.

In this state, getParent() results in a null value.

I thought A would come, but can anyone explain why this is?,,,,

activity getparent

2022-09-22 16:13

1 Answers

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.


2022-09-22 16:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.