将两个截击请求中的值传递给活动

时间:2017-03-27 06:35:20

标签: android android-intent parameter-passing android-volley

所以我在MainActivity上发出了两个截击请求。两者都返回一个JSONArray然后我解析成ArrayList。

我的问题是有没有办法将这两个arrayLists从MainActivity传递给MainActivity2?

MainActivity类:

public class MainActivity extends AppCompatActivity {

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

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                final Intent mainIntent = new Intent(SplashScreen.this, MainActivity.class);
                SplashScreen.this.startActivity(mainIntent);
                SplashScreen.this.finish();
            }
        }, 5000);
    }

    public void getAtm1(Context context){
        VolleyRequests.getJson(RequestURL.getAtmURL(),context, new VolleyJsonListener() {
            @Override
            public void onResponse(JSONArray response) {
               ArrayList<Atm> atmArrayList1 = XmlHandler.getAtmArrayList(response);
            }
            @Override
            public void onError(String error) {
                // error
                Toast.makeText(getApplicationContext(),"Something went wrong. Please try again later",Toast.LENGTH_LONG).show();
                Log.d("Error.Response","Error"+ error);
            }
        });
    }
    public void getAtm2(Context context){
        VolleyRequests.getJson(RequestURL.getAtmURL(),context, new VolleyJsonListener() {
            @Override
            public void onResponse(JSONArray response) {
                ArrayList<Atm> atmArrayList2 = XmlHandler.getAtmArrayList(response);
            }
            @Override
            public void onError(String error) {
                // error
                Toast.makeText(getApplicationContext(),"Something went wrong. Please try again later",Toast.LENGTH_LONG).show();
                Log.d("Error.Response","Error"+ error);
            }
        });
    }
}

0 个答案:

没有答案