Skip to content Skip to sidebar Skip to footer

Android Passing Jsonarray From One Intent To Another

Been trying this for a while now. I am trying to pass JsonArray from one intent to another. Here is my code. Intent intent = new Intent(this, DownloadService.class); Bundle bundle

Solution 1:

I do your work like this . please you check this way.

Bundleextras= getIntent().getExtras();
    userName = extras.getString("user_name");

    IntentlogIntent=newIntent(HomePage.this, LogIn.class);
    startActivity(logIntent);

retrieve data in other class.

privateBundleextraslogin= getIntent().getExtras();
    userName = extraslogin.getString("user_name");

and also you check , your data assigning part also.i think , this may be some help to you. you try retrieve data other class , within 'onCreat' method. directly like above code.

Solution 2:

I think you have used wrong keys... Please check..

You are putting bundle in Intent with key "deal_list". and in bundle you have jsonarray with key "jsonArray".

So first u should check for key "deal_list", because you put it (bundle) in the Intent. and then from bundle fetch the key "jsonArray".

Check your code once. Bundle bundle = intent.getParcelableExtra("jsonArray");

Here you are doing wrong, directly fetching jsonArray from Intent, instead of first fetching Bundle from intent and then the jsonArray.

check this link, see how we use bundle in Intent. Passing values through bundle and get its value on another activity

Solution 3:

You can pass json array with simple putExtra, like:

Intent intent = newIntent(your_activity.this, new_activity.class);
intent.putExtra("jsonArray", mJsonArray.toString());
startActivity(intent);

Where, mJsonArray is your json array.

And now, in your new_activity.java:

Intent intent = getIntent();
String jsonArray = intent.getStringExtra("jsonArray");

try {
    JSONArray array = newJSONArray(jsonArray);
    System.out.println(array.toString(2));
} catch (JSONException e) {
    e.printStackTrace();
}

Post a Comment for "Android Passing Jsonarray From One Intent To Another"