Android how to wait for code to finish before continuing

前端 未结 5 1304
南笙
南笙 2021-01-17 21:28

I have a method called hostPhoto(); it basically uploads an image to a site and retrieves a link. I then have an other method to post the link to a website.

5条回答
  •  一生所求
    2021-01-17 21:37

    I'm assuming you are (or should be) using a separate thread to asynchronously accomplish this action.

    You need to place the post() in a callback that is called when hostPhoto() is complete.

    Generally I've done this with AsyncTask with Android...

    This provides you the callback onPostExecute() that you can do your post() inside.

提交回复
热议问题