I have a custom class that has numerous objects and values inside of it, what I want is to pass itself (the current instance of the class) to an activity as a reference not as a value, I tried all the answers I found here on stackoverflow (passing it by making the class parcelable) but it just doesn't seem to work as a reference for me, any simple way of doing this by passing the actual reference of my class object? However, I'd like to avoid making a public static variable somewhere and access it from there. Thanks in advance
Asked
Active
Viewed 735 times
3
-
1you need to post the relevant code, otherwise people will have no idea how to help you - i mean really, would you able to help yourself based on what you said here? I think not. – EpicPandaForce May 20 '15 at 13:47
-
Can you show an example? With actual code? – mtyurt May 20 '15 at 13:47
-
1You could use EventBus http://stackoverflow.com/questions/27484245/pass-data-between-two-fragments-without-using-activity/27485289#27485289 – cYrixmorten May 20 '15 at 13:58
-
@EpicPandaForce I can't really post the actual code for security reasons, take a chill pill, if you don't have the answer you don't have to. I just need to call Class B from Class A while passing THIS (Class A) as a reference to the next activity (Class B). So then I can access the actual instance of Class A from Class B (Class B is called from Class A). thanks – LBMLT May 20 '15 at 14:49
-
Doesn't have to be the exact code, you can rename stuff and it'd be the same thing. http://stackoverflow.com/help/mcve and what you seem to be looking for is **Intent extras** and *parcelable*. Parcelable works if you use it right. – EpicPandaForce May 20 '15 at 14:56
-
@EpicPandaForce but would the parcelable pass the class by reference or value? – LBMLT May 20 '15 at 15:10
-
A parcelable essentially makes the class be sliced up into primitives, and is reconstructed on the other side. – EpicPandaForce May 20 '15 at 15:22
-
Are you sending the class from one activity to another activity? – EpicPandaForce May 20 '15 at 15:23
-
@EpicPandaForce I'm sending the class (Class A) - from itself (Class A), to another activity (Class B) and in the other activity (Class B) I need to access the actual class that I passed (Class A). When reading the object (Class A) back I don't want to get a new instance of it, but rather a handle that operates on the exact same object (Class A) that was originally passed. – LBMLT May 20 '15 at 17:39
-
If you need to send class A over and it is an activity, and class B is also an activity, aka you need to send an activity to another activity, then you should rethink your design. There should be no reason for you to pass one activity to another. – EpicPandaForce May 20 '15 at 17:41
-
The question is, can't you use a single Activity, and two Fragments, and the Activity would contain the object that needs to be tinkered with by both fragments? – EpicPandaForce May 20 '15 at 19:41
-
class A is not an activity, it is a custom class, this is my problem. – LBMLT May 21 '15 at 10:08