1

So I encountered a problem about the Intent. A little background:

I have a customed class called Workout (Data structures) with constructor and all this stuff. The point is i want to make an intent which kinda looks like this:

Workout workoutP=new Workout(...);

...

intent.put????("workout", workoutP);

Is there any way to pass it from one activity to another?

Zoe
  • 27,060
  • 21
  • 118
  • 148
  • Possible duplicate of [How to send an object from one Android Activity to another using Intents?](https://stackoverflow.com/questions/2139134/how-to-send-an-object-from-one-android-activity-to-another-using-intents) – Mạnh Quyết Nguyễn May 18 '18 at 09:31
  • Possible duplicate of [How to pass an object from one activity to another on Android](https://stackoverflow.com/questions/2736389/how-to-pass-an-object-from-one-activity-to-another-on-android) – Maarten B May 18 '18 at 09:31

2 Answers2

1
Try this:-

Implement Serializable Interface into Workout class then follow following 

steps

public class Workout implements Serializable


//To pass:
intent.putExtra("YourClass", obj);

// To retrieve object in second Activity
getIntent().getSerializableExtra("YourClass");
Mr. Roshan
  • 1,777
  • 13
  • 33
1

Sending side

intent.putExtra("workout", workoutP);

Receiving side

Intent intent = getIntent();
    Workout objref = (Workout ) intent.getSerializableExtra("workout");
Venki WAR
  • 1,997
  • 4
  • 25
  • 38