I'm currently adding some Twitter functionality into my Android application. However, I'm running into an issue with the TwitterAPIClient service callback. Basically, I've got the following code to get user timeline(s):
ArrayList<NewsFeedItem> items = new ArrayList<NewsFeedItems>();
TwitterCore.getInstance().getApiClient(TwitterCore.getInstance().getSessionManager().getActiveSession()).getStatusesService()
.userTimeline(null,
"<username>",
5,
null,
null,
null,
null,
null,
null,
new Callback<List<Tweet>>() {
@Override
public void success(Result<List<Tweet>> result) {
for (Tweet t : result.data) {
SimpleDateFormat dateFormtter = new SimpleDateFormat("EEE MMM dd HH:mm:ss ZZZZ yyyy");
Date d;
try {
d = dateFormtter.parse(t.createdAt);
} catch (ParseException e) {
d = new Date();
}
items.add(new NewsFeedItem(truckIntegrator.getTruckByTruckID(user.getTruckID()), t.text, d));
}
}
}
@Override
public void failure(TwitterException exception) {
android.util.Log.d("twittercommunity", "exception " + exception);
}
});
Which works, however, the execution of code continues after that. Is there a suggested way to pause the execution of the thread this code is running in until success()
is called? This is not running in the main thread by the way. I've tried using wait()
and notify()
, however, that doesn't seem to be working... Thanks!