I'm working on an Android app, which uses an online service, which i need to load my Fragments. Basically, i have like a menu, and each button replaces a Fragment underneath. When I click a button, the fragment starts being replaced, and if I press another button from my keyboard on the meantime, i get the Application Not Responding dialog, and then i click Wait, and my Fragment loads successfully. Is there a way to prevent that from happening? My app will always take a few seconds to load, because of the web service. I read on Google, that i could use AsyncTask, and finish the loading on the DoOnBackground method.. I don't know if that works, but I can't even try, because it won't let me change the view there, it throws an error about only the original thread can change the views.. and I need the service to finish loading my view, so i can't even do the service with the AsyncTask.. I'm running out of ideas now! there has to be a way to do this.. I appreciate suggestions!
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You have to do changes to the ui in the onPostExecute() function of your AsyncTask.
Yes: don't take so long on the main application thread. Use
StrictMode
to identify likely culprits (disk I/O, network I/O), and use Traceview to find out what else you are doing that might be taking too long.That should be done in a background thread.
Which is why you update the views from the
onPostExecute()
method, as is described in the documentation forAsyncTask
.Never execute a database operation or content provider operation in the context of the main thred. sooner or later you will be running into application Not Responding errors. the ANRs are not a good practice.