2

Been a lurker on this site to help find answers to some of my problems before, but I am currently stuck on this and could not find a recent solution. The closest answers I found to my problem were Yelp API Android Integration and Yelp Integration in Android

I tried following the steps in the 2nd link but they are a bit outdated. I have registered for an API, downloaded the jar files from the github and synced them, and made the YelpAPI.java and TwoStepOAuth.java files and removed the main method from YelpAPI. I am stuck on step 4 on the search part. I tried to call the queryAPI method from inside an onClick method I made for a button

    public void getRandom(View view) {
    Intent intent = new Intent(this, SecondActivity.class);
    startActivity(intent);
    YelpAPI.YelpAPICLI yelpApiCli = new YelpAPI.YelpAPICLI();
    new JCommander(yelpApiCli);
    YelpAPI yelpApi = new YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET);
    try {
        YelpAPI.queryAPI(yelpApi, yelpApiCli);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

Basically what I want this to do is, when the button is pressed, I want it to go to a second screen that will display what I query Yelp for. I haven't worked on that part yet, right now I just want to get a result back from Yelp. Keep in mind I am a complete noob at Android Studio and at most intermediate at Java.

Any help is greatly appreciated, it seems like its a really simple problem but its taking me forever to figure out on my own.

Community
  • 1
  • 1

1 Answers1

0

You can't do blocking task like downloading or image loading in android's Main thread (UI Thread). You can't block UI for more than 5 seconds. If you try it to block for more than 5 seconds than your app will stop working and display "Unfornutaley your app has stopped working" because of error too much work on main thread. So you need to make use of async task.

rUCHit31
  • 334
  • 1
  • 3
  • 15