I need to be able to use one object in multiple activities within my app, and it needs to be the same object. What is the best way to do this?
I have tried making the object "public static" so it can be accessed by other activities, but for some reason this just isn't cutting it. Is there another way of doing this?
When you are creating an object of intent, you can take advantage of following two methods for passing objects between two activities.
Here is a small snippet of code I am using
CustomListing currentListing = new CustomListing(); Intent i = new Intent(); Bundle b = new Bundle(); b.putParcelable(Constants.CUSTOM_LISTING, currentListing); i.putExtras(b); i.setClass(this, SearchDetailsActivity.class); startActivity(i);
And in newly started activity code will be something like this...
Bundle b = this.getIntent().getExtras(); if (b != null) mCurrentListing = b.getParcelable(Constants.CUSTOM_LISTING);