title: How to Store JSON data in SharedPrefrence and access offline
body: <p>How to save the JSON in shared preference and fetch the value from local also the verse keeps updating every day, so the shared preference also need to check online for the updated content on how to implement this</p>
  
  <p>public class VOTD_Data extends AsyncTask {</p>
  
  <pre><code>private String verseData = "";
  private String dailyverse = "";
  private String verseauthor = "";
  
  private Context context;
  
  public VOTD_Data(Context context){
      this.context = context;
  }
  
  
  @Override
  protected Void doInBackground(Void... voids) {
  
  
      try {
          URL url = new URL("https://beta.ourmanna.com/api/v1/get/?format=json");
  
          HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
  
          InputStream inputStream = httpURLConnection.getInputStream();
          BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
  
          String line = "";
  
          while (line != null){
  
              line = bufferedReader.readLine();
              verseData  = verseData + line;
          }
  
  
          JSONObject mainObject = new JSONObject(verseData).getJSONObject("verse");
          JSONObject verseObject = mainObject.getJSONObject("details");
  
  
  
          dailyverse = verseObject.getString("text");
          verseauthor = verseObject.getString("reference");
  
          PreferenceManager
                  .getDefaultSharedPreferences(context)
                  .edit()
                  .putString("dailyverse", dailyverse)
                  .putString("verseauthor", verseauthor)
                  .apply();
  
  
      } catch (IOException | JSONException e) {
          e.printStackTrace();
      }
  
      return null;
  }
  
  @Override
  protected void onPostExecute(Void aVoid) {
      super.onPostExecute(aVoid);
  
      Fragment_Home.dailyVerse.setText(this.dailyverse);
      Fragment_Home.verseAuthor.setText(this.verseauthor);
  
  }
  }
  </code></pre>
  
  <p>Home Fragment</p>
  
  <p>public class Fragment_Home extends Fragment {</p>
  
  <pre><code>    public static TextView dailyVerse;
      public static TextView verseAuthor;
  
  
  
      @Nullable
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.fragment_home, container, false);
  
  
          dailyVerse = (TextView) rootView.findViewById(R.id.daily_verse);
          verseAuthor = (TextView) rootView.findViewById(R.id.verse_author);
  
  
          //BindMethod
          fetchDailyVerseData();
  
  
          return rootView;
      }
  
      private void fetchDailyVerseData() {
  //        VOTD_Data process = new VOTD_Data();
  //        process.execute();
  
          new VOTD_Data(getContext()).execute();
      }
  
  
      @Override
      public void onResume() {
          super.onResume();
          requireActivity().setTitle("Home");
      }
  
  
      private class VOTD_DATA extends AsyncTask&lt;Void, Void, Void&gt; {
  
          @Override
          protected Void doInBackground(Void... voids) {
              PreferenceManager
                      .getDefaultSharedPreferences(getActivity())
                      .edit()
                      .putString("dailyverse", String.valueOf(dailyVerse))
                      .putString("verseauthor", String.valueOf(verseAuthor))
                      .apply();
  
              return null;
  
          }
      }
  </code></pre>