Utilising Parcelable to send Array across two activitiesHow can I concatenate two arrays in Java?How to send an object from one Android Activity to another using Intents?Android: Parcelable.writeToParcel and Parcelable.Creator.createFromParcel are never calledCalling the finish() method of an Activity from a BroadcastReceiverActivity called from serviceandroid tabbar on every activityNullPointerException when trying to read parcel ArrayList<Object>android logic error with embedding an adView within a listview fragment - latest admob sdk - revised using XML and JavasetText on button from another activity androidHow to implement parcelable with my custom class containing Hashmap and SparseArray?

How do I write bicross product symbols in latex?

Why do I get two different answers for this counting problem?

What exploit are these user agents trying to use?

I Accidentally Deleted a Stock Terminal Theme

Is the Joker left-handed?

What is the intuition behind short exact sequences of groups; in particular, what is the intuition behind group extensions?

What is the most common color to indicate the input-field is disabled?

In a spin, are both wings stalled?

Brothers & sisters

Arrow those variables!

Emailing HOD to enhance faculty application

Western buddy movie with a supernatural twist where a woman turns into an eagle at the end

Should I tell management that I intend to leave due to bad software development practices?

Twin primes whose sum is a cube

What does it mean to describe someone as a butt steak?

Infinite Abelian subgroup of infinite non Abelian group example

Has there ever been an airliner design involving reducing generator load by installing solar panels?

What about the virus in 12 Monkeys?

Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?

90's TV series where a boy goes to another dimension through portal near power lines

Why does Arabsat 6A need a Falcon Heavy to launch

Fully-Firstable Anagram Sets

I'm flying to France today and my passport expires in less than 2 months

Intersection of two sorted vectors in C++



Utilising Parcelable to send Array across two activities


How can I concatenate two arrays in Java?How to send an object from one Android Activity to another using Intents?Android: Parcelable.writeToParcel and Parcelable.Creator.createFromParcel are never calledCalling the finish() method of an Activity from a BroadcastReceiverActivity called from serviceandroid tabbar on every activityNullPointerException when trying to read parcel ArrayList<Object>android logic error with embedding an adView within a listview fragment - latest admob sdk - revised using XML and JavasetText on button from another activity androidHow to implement parcelable with my custom class containing Hashmap and SparseArray?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm trying to send a populated array of a created class called 'Exercise' between two activities, and I've read the best way to do so I utilising the Parcelable class.



Activity 2 crashes whenever it starts. I've followed tutorials online for this and this is how they treat the sending of the data.



Exercise Class:



import android.os.Parcel;
import android.os.Parcelable;

public class Exercise implements Parcelable

public String Name = "";
public int Time = 0;
public boolean SwitchDirection = false;

Exercise(String n, int l, boolean s)
Name = n;
Time = l;
SwitchDirection = s;


protected Exercise(Parcel in)
Name = in.readString();
Time = in.readInt();
SwitchDirection = in.readByte() != 0;


@Override
public int describeContents()
return 0;


@Override
public void writeToParcel(Parcel dest, int flags)
dest.writeString(Name);
dest.writeInt(Time);
dest.writeByte((byte) (SwitchDirection ? 1 : 0));


public static final Creator<Exercise> CREATOR = new Creator<Exercise>()
@Override
public Exercise createFromParcel(Parcel in)
return new Exercise(in);


@Override
public Exercise[] newArray(int size)
return new Exercise[size];

;



Activity 1:



 Exercise[] Exercises = new Exercise[]
new Exercise("Scisssors", 60, false),
new Exercise("Cross Knee Planks", 60, false),
new Exercise("Twisting Pistons", 30, false),
new Exercise("Accordion Crunches", 60, true),
new Exercise("Canoe Crunch", 30, false),
new Exercise("Upper Circle Crunches", 30, true)
;


Intent i = new Intent(this, Activity2.class);
i.putExtra("Exercises", Exercises);
startActivity(i);


Activity 2:



 Exercise[] Exercises;
Exercises = (Exercise[]) getIntent().getParcelableArrayExtra("Exercises");









share|improve this question






















  • I can't see anything wrong with it from a quick glance, but seeing as you're trying to parcel an array, can the crash be an TransactionTooLargeException?

    – Mauro Curbelo
    Mar 8 at 0:53

















0















I'm trying to send a populated array of a created class called 'Exercise' between two activities, and I've read the best way to do so I utilising the Parcelable class.



Activity 2 crashes whenever it starts. I've followed tutorials online for this and this is how they treat the sending of the data.



Exercise Class:



import android.os.Parcel;
import android.os.Parcelable;

public class Exercise implements Parcelable

public String Name = "";
public int Time = 0;
public boolean SwitchDirection = false;

Exercise(String n, int l, boolean s)
Name = n;
Time = l;
SwitchDirection = s;


protected Exercise(Parcel in)
Name = in.readString();
Time = in.readInt();
SwitchDirection = in.readByte() != 0;


@Override
public int describeContents()
return 0;


@Override
public void writeToParcel(Parcel dest, int flags)
dest.writeString(Name);
dest.writeInt(Time);
dest.writeByte((byte) (SwitchDirection ? 1 : 0));


public static final Creator<Exercise> CREATOR = new Creator<Exercise>()
@Override
public Exercise createFromParcel(Parcel in)
return new Exercise(in);


@Override
public Exercise[] newArray(int size)
return new Exercise[size];

;



Activity 1:



 Exercise[] Exercises = new Exercise[]
new Exercise("Scisssors", 60, false),
new Exercise("Cross Knee Planks", 60, false),
new Exercise("Twisting Pistons", 30, false),
new Exercise("Accordion Crunches", 60, true),
new Exercise("Canoe Crunch", 30, false),
new Exercise("Upper Circle Crunches", 30, true)
;


Intent i = new Intent(this, Activity2.class);
i.putExtra("Exercises", Exercises);
startActivity(i);


Activity 2:



 Exercise[] Exercises;
Exercises = (Exercise[]) getIntent().getParcelableArrayExtra("Exercises");









share|improve this question






















  • I can't see anything wrong with it from a quick glance, but seeing as you're trying to parcel an array, can the crash be an TransactionTooLargeException?

    – Mauro Curbelo
    Mar 8 at 0:53













0












0








0








I'm trying to send a populated array of a created class called 'Exercise' between two activities, and I've read the best way to do so I utilising the Parcelable class.



Activity 2 crashes whenever it starts. I've followed tutorials online for this and this is how they treat the sending of the data.



Exercise Class:



import android.os.Parcel;
import android.os.Parcelable;

public class Exercise implements Parcelable

public String Name = "";
public int Time = 0;
public boolean SwitchDirection = false;

Exercise(String n, int l, boolean s)
Name = n;
Time = l;
SwitchDirection = s;


protected Exercise(Parcel in)
Name = in.readString();
Time = in.readInt();
SwitchDirection = in.readByte() != 0;


@Override
public int describeContents()
return 0;


@Override
public void writeToParcel(Parcel dest, int flags)
dest.writeString(Name);
dest.writeInt(Time);
dest.writeByte((byte) (SwitchDirection ? 1 : 0));


public static final Creator<Exercise> CREATOR = new Creator<Exercise>()
@Override
public Exercise createFromParcel(Parcel in)
return new Exercise(in);


@Override
public Exercise[] newArray(int size)
return new Exercise[size];

;



Activity 1:



 Exercise[] Exercises = new Exercise[]
new Exercise("Scisssors", 60, false),
new Exercise("Cross Knee Planks", 60, false),
new Exercise("Twisting Pistons", 30, false),
new Exercise("Accordion Crunches", 60, true),
new Exercise("Canoe Crunch", 30, false),
new Exercise("Upper Circle Crunches", 30, true)
;


Intent i = new Intent(this, Activity2.class);
i.putExtra("Exercises", Exercises);
startActivity(i);


Activity 2:



 Exercise[] Exercises;
Exercises = (Exercise[]) getIntent().getParcelableArrayExtra("Exercises");









share|improve this question














I'm trying to send a populated array of a created class called 'Exercise' between two activities, and I've read the best way to do so I utilising the Parcelable class.



Activity 2 crashes whenever it starts. I've followed tutorials online for this and this is how they treat the sending of the data.



Exercise Class:



import android.os.Parcel;
import android.os.Parcelable;

public class Exercise implements Parcelable

public String Name = "";
public int Time = 0;
public boolean SwitchDirection = false;

Exercise(String n, int l, boolean s)
Name = n;
Time = l;
SwitchDirection = s;


protected Exercise(Parcel in)
Name = in.readString();
Time = in.readInt();
SwitchDirection = in.readByte() != 0;


@Override
public int describeContents()
return 0;


@Override
public void writeToParcel(Parcel dest, int flags)
dest.writeString(Name);
dest.writeInt(Time);
dest.writeByte((byte) (SwitchDirection ? 1 : 0));


public static final Creator<Exercise> CREATOR = new Creator<Exercise>()
@Override
public Exercise createFromParcel(Parcel in)
return new Exercise(in);


@Override
public Exercise[] newArray(int size)
return new Exercise[size];

;



Activity 1:



 Exercise[] Exercises = new Exercise[]
new Exercise("Scisssors", 60, false),
new Exercise("Cross Knee Planks", 60, false),
new Exercise("Twisting Pistons", 30, false),
new Exercise("Accordion Crunches", 60, true),
new Exercise("Canoe Crunch", 30, false),
new Exercise("Upper Circle Crunches", 30, true)
;


Intent i = new Intent(this, Activity2.class);
i.putExtra("Exercises", Exercises);
startActivity(i);


Activity 2:



 Exercise[] Exercises;
Exercises = (Exercise[]) getIntent().getParcelableArrayExtra("Exercises");






java android parcelable






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 0:24









Liam_FothLiam_Foth

82




82












  • I can't see anything wrong with it from a quick glance, but seeing as you're trying to parcel an array, can the crash be an TransactionTooLargeException?

    – Mauro Curbelo
    Mar 8 at 0:53

















  • I can't see anything wrong with it from a quick glance, but seeing as you're trying to parcel an array, can the crash be an TransactionTooLargeException?

    – Mauro Curbelo
    Mar 8 at 0:53
















I can't see anything wrong with it from a quick glance, but seeing as you're trying to parcel an array, can the crash be an TransactionTooLargeException?

– Mauro Curbelo
Mar 8 at 0:53





I can't see anything wrong with it from a quick glance, but seeing as you're trying to parcel an array, can the crash be an TransactionTooLargeException?

– Mauro Curbelo
Mar 8 at 0:53












1 Answer
1






active

oldest

votes


















0














I think you don't should send and get an array of Parcelable. You should give an array for Parcelable, and get it in Activity 2.
I have an example that send a HashMap between 2 activities.



public class BaseData implements Parcelable 

protected HashMap<String, Object> mData;

public BaseData(HashMap<String, Object> data)
mData = data;


protected BaseData(Parcel in)
try
mData = in.readHashMap(HashMap.class.getClassLoader());
catch (Exception e)
e.printStackTrace();



public static final Creator<BaseData> CREATOR = new Creator<BaseData>()
@Override
public BaseData createFromParcel(Parcel in)
return new BaseData(in);


@Override
public BaseData[] newArray(int size)
return new BaseData[size];

;

@Override
public int describeContents()
return 0;


@Override
public void writeToParcel(Parcel dest, int flags)
try

if (null == mData)
return;


dest.writeValue(mData);
catch (Exception e)




public HashMap<String, Object> getData()
return mData;





In Activty 1 you will send data like that:



 HashMap<String, Object> hm = new HashMap<>();
hm.put("data_1", array_data_1);
hm.put("data_2",array_data_2);
BaseData baseData = new BaseData(hm);
BaseData baseData = new BaseData(data);
Bundle bundle = new Bundle();
bundle.putParcelable("base_data", baseData);
Intent intent = new Intent(context,Activity2.class)
intent.putExtra("data",bundle);


In Activy 2 you will receive a bundle, then get basedata from bundle and get HashMap from basedata.



 Bundle bundle = getIntent().getBundleExtra("data");
BaseData baseData = bundle.getParcelable("base_data");
HashMap<String,Object> hm = baseData.getData();


You can replace HashMap by Array. If you can't implement it, please tell me I will send you a complete example.






share|improve this answer

























  • Would you be able to include your code for receiving the hashmap on Activity2?

    – Liam_Foth
    Mar 8 at 1:04











  • I updated my answer. Please check it

    – NhatVM
    Mar 8 at 1:21












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054970%2futilising-parcelable-to-send-array-across-two-activities%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I think you don't should send and get an array of Parcelable. You should give an array for Parcelable, and get it in Activity 2.
I have an example that send a HashMap between 2 activities.



public class BaseData implements Parcelable 

protected HashMap<String, Object> mData;

public BaseData(HashMap<String, Object> data)
mData = data;


protected BaseData(Parcel in)
try
mData = in.readHashMap(HashMap.class.getClassLoader());
catch (Exception e)
e.printStackTrace();



public static final Creator<BaseData> CREATOR = new Creator<BaseData>()
@Override
public BaseData createFromParcel(Parcel in)
return new BaseData(in);


@Override
public BaseData[] newArray(int size)
return new BaseData[size];

;

@Override
public int describeContents()
return 0;


@Override
public void writeToParcel(Parcel dest, int flags)
try

if (null == mData)
return;


dest.writeValue(mData);
catch (Exception e)




public HashMap<String, Object> getData()
return mData;





In Activty 1 you will send data like that:



 HashMap<String, Object> hm = new HashMap<>();
hm.put("data_1", array_data_1);
hm.put("data_2",array_data_2);
BaseData baseData = new BaseData(hm);
BaseData baseData = new BaseData(data);
Bundle bundle = new Bundle();
bundle.putParcelable("base_data", baseData);
Intent intent = new Intent(context,Activity2.class)
intent.putExtra("data",bundle);


In Activy 2 you will receive a bundle, then get basedata from bundle and get HashMap from basedata.



 Bundle bundle = getIntent().getBundleExtra("data");
BaseData baseData = bundle.getParcelable("base_data");
HashMap<String,Object> hm = baseData.getData();


You can replace HashMap by Array. If you can't implement it, please tell me I will send you a complete example.






share|improve this answer

























  • Would you be able to include your code for receiving the hashmap on Activity2?

    – Liam_Foth
    Mar 8 at 1:04











  • I updated my answer. Please check it

    – NhatVM
    Mar 8 at 1:21
















0














I think you don't should send and get an array of Parcelable. You should give an array for Parcelable, and get it in Activity 2.
I have an example that send a HashMap between 2 activities.



public class BaseData implements Parcelable 

protected HashMap<String, Object> mData;

public BaseData(HashMap<String, Object> data)
mData = data;


protected BaseData(Parcel in)
try
mData = in.readHashMap(HashMap.class.getClassLoader());
catch (Exception e)
e.printStackTrace();



public static final Creator<BaseData> CREATOR = new Creator<BaseData>()
@Override
public BaseData createFromParcel(Parcel in)
return new BaseData(in);


@Override
public BaseData[] newArray(int size)
return new BaseData[size];

;

@Override
public int describeContents()
return 0;


@Override
public void writeToParcel(Parcel dest, int flags)
try

if (null == mData)
return;


dest.writeValue(mData);
catch (Exception e)




public HashMap<String, Object> getData()
return mData;





In Activty 1 you will send data like that:



 HashMap<String, Object> hm = new HashMap<>();
hm.put("data_1", array_data_1);
hm.put("data_2",array_data_2);
BaseData baseData = new BaseData(hm);
BaseData baseData = new BaseData(data);
Bundle bundle = new Bundle();
bundle.putParcelable("base_data", baseData);
Intent intent = new Intent(context,Activity2.class)
intent.putExtra("data",bundle);


In Activy 2 you will receive a bundle, then get basedata from bundle and get HashMap from basedata.



 Bundle bundle = getIntent().getBundleExtra("data");
BaseData baseData = bundle.getParcelable("base_data");
HashMap<String,Object> hm = baseData.getData();


You can replace HashMap by Array. If you can't implement it, please tell me I will send you a complete example.






share|improve this answer

























  • Would you be able to include your code for receiving the hashmap on Activity2?

    – Liam_Foth
    Mar 8 at 1:04











  • I updated my answer. Please check it

    – NhatVM
    Mar 8 at 1:21














0












0








0







I think you don't should send and get an array of Parcelable. You should give an array for Parcelable, and get it in Activity 2.
I have an example that send a HashMap between 2 activities.



public class BaseData implements Parcelable 

protected HashMap<String, Object> mData;

public BaseData(HashMap<String, Object> data)
mData = data;


protected BaseData(Parcel in)
try
mData = in.readHashMap(HashMap.class.getClassLoader());
catch (Exception e)
e.printStackTrace();



public static final Creator<BaseData> CREATOR = new Creator<BaseData>()
@Override
public BaseData createFromParcel(Parcel in)
return new BaseData(in);


@Override
public BaseData[] newArray(int size)
return new BaseData[size];

;

@Override
public int describeContents()
return 0;


@Override
public void writeToParcel(Parcel dest, int flags)
try

if (null == mData)
return;


dest.writeValue(mData);
catch (Exception e)




public HashMap<String, Object> getData()
return mData;





In Activty 1 you will send data like that:



 HashMap<String, Object> hm = new HashMap<>();
hm.put("data_1", array_data_1);
hm.put("data_2",array_data_2);
BaseData baseData = new BaseData(hm);
BaseData baseData = new BaseData(data);
Bundle bundle = new Bundle();
bundle.putParcelable("base_data", baseData);
Intent intent = new Intent(context,Activity2.class)
intent.putExtra("data",bundle);


In Activy 2 you will receive a bundle, then get basedata from bundle and get HashMap from basedata.



 Bundle bundle = getIntent().getBundleExtra("data");
BaseData baseData = bundle.getParcelable("base_data");
HashMap<String,Object> hm = baseData.getData();


You can replace HashMap by Array. If you can't implement it, please tell me I will send you a complete example.






share|improve this answer















I think you don't should send and get an array of Parcelable. You should give an array for Parcelable, and get it in Activity 2.
I have an example that send a HashMap between 2 activities.



public class BaseData implements Parcelable 

protected HashMap<String, Object> mData;

public BaseData(HashMap<String, Object> data)
mData = data;


protected BaseData(Parcel in)
try
mData = in.readHashMap(HashMap.class.getClassLoader());
catch (Exception e)
e.printStackTrace();



public static final Creator<BaseData> CREATOR = new Creator<BaseData>()
@Override
public BaseData createFromParcel(Parcel in)
return new BaseData(in);


@Override
public BaseData[] newArray(int size)
return new BaseData[size];

;

@Override
public int describeContents()
return 0;


@Override
public void writeToParcel(Parcel dest, int flags)
try

if (null == mData)
return;


dest.writeValue(mData);
catch (Exception e)




public HashMap<String, Object> getData()
return mData;





In Activty 1 you will send data like that:



 HashMap<String, Object> hm = new HashMap<>();
hm.put("data_1", array_data_1);
hm.put("data_2",array_data_2);
BaseData baseData = new BaseData(hm);
BaseData baseData = new BaseData(data);
Bundle bundle = new Bundle();
bundle.putParcelable("base_data", baseData);
Intent intent = new Intent(context,Activity2.class)
intent.putExtra("data",bundle);


In Activy 2 you will receive a bundle, then get basedata from bundle and get HashMap from basedata.



 Bundle bundle = getIntent().getBundleExtra("data");
BaseData baseData = bundle.getParcelable("base_data");
HashMap<String,Object> hm = baseData.getData();


You can replace HashMap by Array. If you can't implement it, please tell me I will send you a complete example.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 8 at 1:23

























answered Mar 8 at 0:54









NhatVMNhatVM

43739




43739












  • Would you be able to include your code for receiving the hashmap on Activity2?

    – Liam_Foth
    Mar 8 at 1:04











  • I updated my answer. Please check it

    – NhatVM
    Mar 8 at 1:21


















  • Would you be able to include your code for receiving the hashmap on Activity2?

    – Liam_Foth
    Mar 8 at 1:04











  • I updated my answer. Please check it

    – NhatVM
    Mar 8 at 1:21

















Would you be able to include your code for receiving the hashmap on Activity2?

– Liam_Foth
Mar 8 at 1:04





Would you be able to include your code for receiving the hashmap on Activity2?

– Liam_Foth
Mar 8 at 1:04













I updated my answer. Please check it

– NhatVM
Mar 8 at 1:21






I updated my answer. Please check it

– NhatVM
Mar 8 at 1:21




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054970%2futilising-parcelable-to-send-array-across-two-activities%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко