1

I have a fragment that creates a view, this view uses other classes and methods, but I want after create the view (inflated and initialized) is visible to the user call a method that is going to display the data usage per app.

Is there a way i can run a method after everything is inflated and initialized?

Thanks

Ophy
  • 81
  • 1
  • 12
  • Some code will be much more easier for us to help. `Is there a way i can run a method after everything is inflated and initialized?` Of course, you can run any method you like anywhere. But what is the real question here, what kind of `data usage` you want to show? – Tam Huynh May 18 '18 at 16:43

2 Answers2

0

try running it into onResume()

It is the last called method of the fragment lifecycle

firegloves
  • 5,581
  • 2
  • 29
  • 50
0

The view does not load until the method is over

That is because you are doing some long task in UI thread. Then even you put that method in onResume() or onStart(), your UI will freeze. You should use AsyncTask if you want do some long thread work after UI is inflated.

see

What is the Android UiThread (UI thread)

https://developer.android.com/topic/performance/threads

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212