How to call Activity methods from inside a Fragment
<p>I've been struggling for a few days trying to get my head around Fragments in Android. At the moment I've created a menu out of buttons that allows the user to switch between Fragments. Each Fragment will then allow the user to to grab a JSON array from a server using a search criteria that is specific to that fragment. </p>

<p>Ideally after each search, the results would remain in memory so that the user could use the menu to switch between the fragments. As the fragments will be using the same methods that currently all sit in the MainActivity, how do I call the methods from MainActivity from inside the fragments? </p>

<p>My code for a method in Activity:</p>

<pre><code>  public ArrayList&lt;Eatery&gt; fillArray() {

    String line;
    Eatery eatery = new Eatery("hello","hello","hello","hello","hello",
            "hello","hello","hello","hello","hello");
    ArrayList&lt;Eatery&gt; eateryList = new ArrayList&lt;&gt;();

    if (getConnection() == true) {
        try {

            URL nameURL = new URL("http://sandbox.kriswelsh.com/hygieneapi/hygiene.php?op=s_name&amp;name=Wok%20This%20Way");
            HttpURLConnection postcodeConnection = (HttpURLConnection) nameURL.openConnection();
            InputStreamReader isr = new InputStreamReader(postcodeConnection.getInputStream());
            BufferedReader nameBF = new BufferedReader(isr);

            while ((line = nameBF.readLine()) != null) {
                JSONArray ja = new JSONArray(line);
                for (int i = 0; i &lt; ja.length(); i++) {

                    JSONObject jo = ja.getJSONObject(i);
                    String id = jo.getString("id");
                    String businessName = jo.getString("BusinessName");
                    String addressLine1 = jo.getString("AddressLine1");
                    String addressLine2 = jo.getString("AddressLine2");
                    String addressLine3 = jo.getString("AddressLine3");
                    String postcode = jo.getString("PostCode");
                    String ratingValue = jo.getString("RatingValue");
                    String ratingDate = jo.getString("RatingDate");
                    String lati = jo.getString("Latitude");
                    String longi = jo.getString("Longitude");
                    eatery.setId(id);
                    eatery.setBusinessName(businessName);
                    eatery.setAddressLine1(addressLine1);
                    eatery.setAddressLine2(addressLine2);
                    eatery.setAddressLine3(addressLine3);
                    eatery.setPostcode(postcode);
                    eatery.setRatingValue(ratingValue);
                    eatery.setRatingDate(ratingDate);
                    eatery.setLati(lati);
                    eatery.setLati(longi);
                    eateryList.add(eatery);
                }
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        Toast nameToast = Toast.makeText(getApplicationContext(), "Error: No Active Connection", Toast.LENGTH_LONG);
        nameToast.show();
    }

    return (eateryList);
}
</code></pre>