You can make your complex objects public
and static
in ActivityA
, and access them in ActivityB
like this:
MyCustomObjectType complexFromA = ActivityA.complexObject;
this will work, however while in ActivityB
, you can't always be sure that static objects from ActivityA
will exist(they may be null) since Android may terminate your application.
so then maybe add some null checking:
if(null == ActivityA.complexObject) {
//go back to ActivityA, or do something else since the object isn't there
}
else {
//business as usual, access the object
MyCustomObjectType complexFromA = ActivityA.complexObject;
}
You could also use a Singleton object which extends Application
. You would have the same problem when Android terminates your application. always need to check if the object actually exists. Using the Singleton extending Application
approach seems to be the more organized way - but adds more complexity to implementation. just depends what you need to do and whatever works for your implementation.