Hello, tell me how to correctly transfer the values of a variable, here is the code
public class MainActivity extends WorkService { public int buy; public class TextRequestListener implements RequestListener<String> { @Override public void onRequestFailure(SpiceException spiceException) { //Toast.makeText(MainActivity.this, "failure", Toast.LENGTH_SHORT).show(); Log.d(TAG,"failure"); } @Override public void onRequestSuccess(final String result) { //Toast.makeText(MainActivity.this, "success", Toast.LENGTH_SHORT).show(); Log.d(TAG,"success"); Log.d(TAG,result); //парсинг ответа, JSON try { dataJsonObj = new JSONObject(result); JSONObject sys = dataJsonObj.getJSONObject("query"); JSONObject sys1 = sys.getJSONObject("results"); JSONObject sys2 = sys1.getJSONObject("rate"); buy = sys2.getInt("Ask"); } catch (JSONException e) { e.printStackTrace(); } Log.d(TAG,"buy = " + buy); } } public int getBuy(){ return buy; }` The TextRequestListener class is nested in the MainActivity class. I need to pass this line to buy = sys2.getInt ("Ask"); to another class. Tried to do so, but it does not work.
MainActivity a = new MainActivity(); MainActivity.TextRequestListener b = a.new TextRequestListener(); int buy = b.buy; Log.d(TAG, "buy= " + buy); or
MainActivity main = (MainActivity)getActivity(); int s = main.getBuy(); in two cases I get zero.