i have a data that i got from json. and i need that data to every activity in my project. if i pass it using getExtra
with intent when i back to other activity the data may lost. so i want to make a class that can keep the data so i can call it in every activity when i need it. is it possible? if yes how?
this is my example code when i call json. and maybe i think i want to make this call function to another class so i can call the data in every activity
try {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://example.com/user")
.get()
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + token)
.addHeader("Cache-Control", "no-cache")
.addHeader("Postman-Token", "e03845a5-dcb4-4835-9a9a-e9574fb5ed73")
.build();
Response response = client.newCall(request).execute();
Log.d("respon after token", "" + response);
Log.d("json", "" + response.body().string());
String jsonData = response.body().string();
JSONObject object = new JSONObject(jsonData);
token = object.getString("id");
token = object.getString("name");
token = object.getString("username");
token = object.getString("email");
} catch (IOException | JSONException e) {
e.printStackTrace();
}