简体   繁体   中英

ViewPager using Fragment

I am using ViewPager which uses three Fragments, and one of the Fragments uses database operations. So when I launch my application it takes much time to load(because of databse operation) and it crashes most of the time. I used AsyncTask for databse operations in Fragment but still this problem is there. Any other solutions ??

Have you already considered these rules for AsyncTasks?

There are a few threading rules that must be followed for this class to work properly:

  • The AsyncTask class must be loaded on the UI thread. This is done automatically as of JELLY_BEAN.
  • The task instance must be created on the UI thread. execute(Params...) must be invoked on the UI thread.
  • Do not call onPreExecute(), onPostExecute(Result), doInBackground(Params...), onProgressUpdate(Progress...) manually.
  • The task can be executed only once (an exception will be thrown if a second execution is attempted.)

from: http://developer.android.com/reference/android/os/AsyncTask.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM