Pergunta

I have several Fragments (in a NavigationDrawer) in which, when opened, I do a query to have the informations that are displayed in the respectively fragment layout. Till now, every methods are in onActivityCreated method but doing this, the fragment switching is slow. What is the best way for doing what I want?

Foi útil?

Solução

The main strategy - do not block main thread or, in other words, so as less as possible on UI thread.

You can make loading layout for your fragments or "loading" fragment for your activity. While displaying this do data querying in background thread. Update UI when you have all data needed.

Outras dicas

I think your data fetching operations in fragments should be in onCreate() and it should be async and off the UI thread, while for example showing a progress dialog or something to indicate the process to the user.

and in onActivityCreated your should just show that data in your views

and do NOT any processing on the UI thread

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top