0

I am filling a table on tabhost after login. I have set up a thread to fill in the table. Meanwhile I click on the tab where I have set up another thread to read the data from the same table and fill the adapter for the list view.

My problem is that the thread which fills the table on tabhost takes some time and meanwhile if I click on the tab to show the data from table it shows no data found because of the adapter being empty.

How to solve this? Is it something like producer/consumer which can be solved using wait() and notify()?

dda
  • 6,030
  • 2
  • 25
  • 34
Aditya Arora
  • 45
  • 1
  • 8

1 Answers1

0

Easiest (aka hackiest) way I can imagine?

Create a static boolean set to false in your main activity. Have the background thread set it to true once it has updated the data. The other activity can check if the boolean is false and send you back to main or put up a toast stating the data is still loading.

Or just if no data is found, simply put up a toast that you are loading. You can have a timer running to refresh the page until data is found.

TheRealKingK
  • 829
  • 7
  • 14
  • how will the other activity keep on checking for the boolean to be true? do i need to use wait n notify? – Aditya Arora Jan 20 '13 at 06:11
  • If you send them back to main with a toast saying "Still Loading", you only have to check in the onResume(). – TheRealKingK Jan 20 '13 at 06:18
  • no, i dont intend to send them back to main, rather i need to keep the progressdialog on the adapter page to keep loading, until the boolean becomes true and data is filled. should i just use a while loop to keep checking the boolean? – Aditya Arora Jan 20 '13 at 06:23
  • Use a timer to check, then reload the activity. http://developer.android.com/reference/java/util/Timer.html Do not use a while loop because that will block the UI thread. Do not sleep or block the UI thread because that will make your app unresponsive – TheRealKingK Jan 20 '13 at 06:55