title: How to display toast in static method of a Util class?
body: <p>I have the following Utils class and I want to write a friendly toast to my users in the catch block like this:</p>
  
  <pre><code>catch (JSONException e){
    Log.e(LOG_TAG, "String to JSON failed: " + e);
    showToast(getActivity, "Test toast");
  }
  </code></pre>
  
  <p>But the problem is how do I get my activity or application context?
  I tried this   <a href="https://stackoverflow.com/a/23423970">https://stackoverflow.com/a/23423970</a> but it doesn't work for me because I'm not sure where to get my context from? If I have to create a constructor of the Util class then it defeats the purpose of the Util class as I dont want to instantiate this class.</p>
  
  <p>Here's my class:</p>
  
  <pre><code>public class Utils {
    public static boolean showPercent = true;
  
    public static ArrayList quoteJsonToContentVals(String JSON){
      ArrayList&lt;ContentProviderOperation&gt; batchOperations = new ArrayList&lt;&gt;();
      JSONObject jsonObject = null;
      JSONArray resultsArray = null;
      try{
        jsonObject = new JSONObject(JSON);
        if (jsonObject != null &amp;&amp; jsonObject.length() != 0){
          jsonObject = jsonObject.getJSONObject("query");
          int count = Integer.parseInt(jsonObject.getString("count"));
          if (count == 1){
            jsonObject = jsonObject.getJSONObject("results")
                .getJSONObject("quote");
            batchOperations.add(buildBatchOperation(jsonObject));
          } else{
            resultsArray = jsonObject.getJSONObject("results").getJSONArray("quote");
  
            if (resultsArray != null &amp;&amp; resultsArray.length() != 0){
              for (int i = 0; i &lt; resultsArray.length(); i++){
                jsonObject = resultsArray.getJSONObject(i);
                batchOperations.add(buildBatchOperation(jsonObject));
              }
            }
          }
        }
      } catch (JSONException e){
        Log.e(LOG_TAG, "String to JSON failed: " + e);
        showToast(getActivity, "Test toast");
      }
      return batchOperations;
    }
  
    public static void showToast(Context context, String text) {
      Toast.makeText(context, text, Toast.LENGTH_LONG).show();
  }
    .....
  </code></pre>