Pass data from api volley to another screen

0

I have an app that gets given via api using volley

My code:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tela1);

        ImageView myImageView = (ImageView) findViewById(R.id.imageView);
        myImageView.setImageResource(R.drawable.imagem);

        requestQueue = Volley.newRequestQueue(this);


        results = (TextView) findViewById(R.id.textView2);
        datav = (TextView) findViewById(R.id.textA);



        JsonArrayRequest arrayreq = new JsonArrayRequest(JsonURL,

                new Response.Listener<JSONArray>() {

                    @Override
                    public void onResponse(JSONArray response) {
                        try {
                            JSONObject obj = response.getJSONObject(0);
                            Double ask = obj.getDouble("ask");
                            String data = obj.getString("create_date");

                            results.setText("Vale R$: " + ask);
                            datav.setText("Atualizado em: " + data);

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }}},

                new Response.ErrorListener() {
                    @Override
                    // Handles errors that occur due to Volley
                    public void onErrorResponse(VolleyError error) {
                        Log.e("Volley", "Error");
                    }
                }
        );

I want to pass the value of the "ask" that is received to another screen, how do I do this?

    
asked by anonymous 03.01.2017 / 19:32

1 answer

2

If you start a new activity you can just put it as Extra in Intent

 Intent intent = new Intent(this,NovaActivity.class);
 intent.putExtra("ask",ask);
 startActivity(intent);

and to recover in the other activity

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getIntent().getDoubleExtra("ask");
}
    
03.01.2017 / 21:06