So I have 3 Activities that need to all have access to the same custom class object (let’s call it ‘a’) created by me when the very first Activity is created.
Because ‘a’ is made up of a whole bunch of non-primitives, I found it difficult to make Serializable or Parcelable. Instead I created a Service that binds to each Activity as they take the forefront, and gives the Activity ‘a’ in OnBind().
Now ‘a’ has a getter that gets another object of a different custom class stored with the same object (let’s call it ‘b’). In all three Activities, I also need to be able to access ‘b’.
If I start the first Activity, use a button to navigate to the second Activity, press the “home” button on my phone, then go back into the application by pressing its icon, then navigate to the third activity by pressing a button, I get a null pointer exception on ‘b’ but not ‘a’.
However if I add a line that prints ‘a’s getter for ‘b’ with sysout in the step where I press a button to get from the second Activity to the third, then there is no null pointer exception.
Does anybody know why this is and how I can resolve the issue?
Seems you want this object
ato always be there!I suggest extending
applicationNow in your Activities:
Finally in your Mainfest: Add to
<application>