Skip to content Skip to sidebar Skip to footer

Passing Dataset Between Activity In MPAndroidChart

I want to display barchart in full screen after clicking on a button but I got an error when passing BarEntry class between activities. android.os.ParcelFormatException: Cannot p

Solution 1:

Add this lib to build.gradle,

compile 'com.google.code.gson:gson:2.8.1'

convert your Arraylist to json using Gson and pass the json string to new activity.

Intent bar = new Intent(ChartRevenueActivity.this, FullscreenActivity.class);
    bar.putExtra("type", "barChart");
    bar.putExtra("barentry",new Gson().toJson(barEntries));
    startActivity(bar);

retrieve the Arraylist in new activity like this,

 ArrayList<BarEntry> barEntries = 
            new Gson().fromJson(getIntent().getStringExtra("barentry"), new TypeToken<ArrayList<BarEntry>>(){}.getType());

Post a Comment for "Passing Dataset Between Activity In MPAndroidChart"