Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to know if a Fragment has finished loading entire content?

Is there anyway to know that a Fragment has finish loading the entire contents of the Fragment?

The reason I'm asking is because in the onResume state when I put the application in the background I Re-Load the Fragment by executing an AsyncTask but I only want to Re-Load the Fragment that was put in the background only if the Fragment has not finished loading the entire contents of the layout (images, shapes, data, etc...)

is there anyway to know if the Fragment has been fully loaded?

like image 647
Eric Bergman Avatar asked Aug 02 '13 15:08

Eric Bergman


People also ask

What is a fragment in Android?

Fragments. A Fragment represents a reusable portion of your app's UI. A fragment defines and manages its own layout, has its own lifecycle, and can handle its own input events. Fragments cannot live on their own--they must be hosted by an activity or another fragment. The fragment’s view hierarchy becomes part of, or attaches to , ...

How to know when a fragment appears on the screen?

You can know the following with the built in method called "onActivityCreated (Bundle)" this method tells that the fragment has been created thus you get to know that the fragment appears on the screen Click here for reference Hope it helps I've looked through what's available without using a base Fragment or Activity class but couldn't find any.

When is the latest result received from a fragment?

A result is received if the Fragment’s lifecycle is at least in the started state If multiple data is passed to the Fragment before it reaches the STARTED state, it’ll only receive the latest value if it eventually reaches the STARTED state. The latest result is received when the Fragment’s lifecycle reaches the started state

What does the fragmentmanager actually do?

They do most everything through their FragmentManager, and propagate their own lifecycle callbacks down to the Fragments so that the fragments will behave appropriately. The onResume and onPause callbacks in fragments only occur when they are first created or when the Activity experiences those callbacks.


1 Answers

If u just want to know when your Fragment layout is fully inflated u might want to use onActivityCreated(Bundle savedInstanceState) that is called after onCreate and onCreateView.
You can find more information about Fragment life-cycle here

Anyway, if u want more accurate answer post some of your code and make and example to better describe your purpose.

like image 116
Roberto Lombardini Avatar answered Sep 19 '22 17:09

Roberto Lombardini