I’m looking for some advice on the best way to implement the task below (my current method is quite naive and is causing me issues)
Here is the run down on what should happen when my app is started:
-
First the user is prompted to login to facebook. I use facebooks
DialogListener to listen for when it completes. -
On completion of above task I use an AsyncFacebookRunner to collect some
information about the user. I use the
AsyncFacebookRunner.RequestListener() to listen for when this
completes. -
On completion of task 2 I store some information in SharedPreferences
This all works splendidly. Here is the issue… I need to use some of said information in a http POST to get data on the server. The data is used to populate a gridview. For this I am using a Asynctask. My problem lies in not knowing when the data is there in SharedPreferences.
As of right now in the doInBackground I have a loop like this:
while (true)
{
if (not a valid value of something in SharedPreferences)
Thread.sleep(500);
else
break
}
Which is incredibly ugly, naive, and is giving me some issues. At this point I feel like I should rewrite the whole thing so hopefully somebody can suggest a better method!
Register an
OnSharedPreferenceChangedListenerwith theSharedPreferencesto be notified of when data changes in it.