开发者

working with asynctask and json parsing simultaneously between two activities

开发者 https://www.devze.com 2023-04-12 07:25 出处:网络
I need some suggestion on how to go about this specific android problem: activity A passes an intent to activity B,

I need some suggestion on how to go about this specific android problem: activity A passes an intent to activity B, B reads it, makes an API call, B re开发者_JAVA技巧ceives response, parses it, and updates its views from the response

now it works fine except fr a 2 second black screen during transition from A to B is asynctask a solution? becoz the parsing data is not much and also is there a way to update UI views frm asynctask


To echo what Lalit said, an AsyncTask will help in this case. The problem that you're having is that doing the API call during onCreate is blocking the activity from updating the UI. If you use an AsyncTask, it will allow the activity to continue rendering the view.

As you're parsing the result, you can update the UI by calling Activity.runOnUiThread() or by putting the UI code in onPostExecute.


I'm not sure if AsyncTask is the best solution for your case. An AsyncTask is very helpful if you need to do something in background and allow the user to do something else in the mean time.

I'd sugest to just use a Thread and define a progressDialog. If you do it this way, your user will see the loading dialog with the spinning circe and not the black screen that looks more like if the App is freezing.

Let me know if you need help with some code samples. Marco :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号