Issue
I am trying to replace a fragment in Android and its taking almost 2-3 seconds to load the fragment into the UI. I am not sure what might be causing the issue because I don't do perform heavy threads in the onCreateView
.
My fragment that is taking too much time to load has the following in its onCreateView
.
Link : Code for my onCreateView
All I do in my onCreateView is play around with the visibility of certain layouts depending upon the data from DB. I don't think that it would take me so much time to load the page, it doesn't make sense to me.
What have I tried so far :
I haven't tried anything solid except the following which are some silly implementations of stupidity or I think so..
Tried to place a major chunk of code in an Async Task but as most of the code requires
setVisibility()
, it doesn't work indoInBackground()
. And adding arunOnUIThread()
is again same as not using a Async Task.I doubted that the fragment manager might be taking some time to load the fragment into UI but when I replaced with another fragment with lesser UI components then it seemed to load fast.I also tried using
getFragmentManager().executePendingTransactions();
.
So thats what I have tried so far but also found out that option 2 is completely unnecessary because the log that I print before the return convertView;
is taking 1-2 seconds to print. I am not sure what is going wrong or where its going wrong. Any help will be much appreciated.
Solution
You don't have to call super.onCreate()
in onCreateView
. Secondly, you are doing too much DB operations in oncreateView
by instructions like dbHelper.getRelationGenderForEdit
etc. You have to perform these operations in the backGroundThread
. You can use Loaders
or AsyncTasks
to achieve this and pass these results to Fragment
and use those values in onCreateView
Hope this helps.
Answered By - Mustansar Saeed
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.