0

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!

Andy Piper
  • 11,422
  • 2
  • 26
  • 49
AndrewSmiley
  • 1,933
  • 20
  • 32
  • 1
    Android does not allows network requests in main thread. Therefore these requests have to be made in another thread. – Pranjal Sahu Jul 31 '15 at 07:15
  • Yes. That's correct. Which I specified in the question... I've since gotten it working. Forgot I asked this one. Once I can grab the code off my Macbook I'll post the answer. – AndrewSmiley Aug 01 '15 at 22:45

0 Answers0