-5

I'm new to android dev and fragments. I have 3 fragments that inherit my main activity. I have a listview in one of these fragments which need to be updated whenever the user creates or visits that fragment, but onResume is triggered through the main activity. How can I tell what fragment the user is on so I can reload the listview accordingly?

Sarodh Uggalla
  • 293
  • 1
  • 4
  • 15

1 Answers1

1

Fragments do not inherit from Activities. If you have a fragment inheriting from an activity, it's not a fragment, it's an activity.

That being said, fragments have a lifecycle same as activities, so you can overwrite the onResume method on your fragments and it will be called when it's resumed.

It would be REALLY helpful and we could assist you much better if you shared with us some of your code so we can see where the error might be and maybe provide you some correct code.

gnardini
  • 73
  • 6
  • What? http://stackoverflow.com/questions/11326155/fragment-onresume-onpause-is-not-called-on-backstack – Sarodh Uggalla Dec 04 '15 at 05:26
  • I am the OP of the question you have linked to. And I would like to know where in that code that I inherited fragment from activity. – Krishnabhadra Apr 04 '16 at 03:59
  • Also, to answer your question, I think you need to get some fundamental understanding of Activity/Fragment life cycle. Create a study project, add some sample fragments to the activity and do some FragmentTransaction between them. Override life cycle methods in each fragment and add a log. You could understand when each method is called by looking at those logs. – Krishnabhadra Apr 04 '16 at 04:01