Possible Duplicate:
How to pass object from one activity to another in Android
While retrieving appSession I get a RunTimeException:
appSession = (ApplicationSession)intent.getParcelableExtra("appSession");
I am creating a app in which at the launch of app I create an ApplicationSession class object. I want to pass this object to all activities upon launch. How do I achieve this?
// app start
// contains data specific to app which I need to use across all activites.
ApplicationSession appSession = new ApplicationSession();
How to pass appSession
to all activites?
Make ApplicationSession
implement
Parcelable
, and when you are starting an Activity
try something like:
ApplicationSession appSession = new ApplicationSession();
Intent i = new Intent(context, YourActivityName.class);
i.putExtra("appSession", appSession);
startActivity(i);
OR if it makes sense in your use case, just make ApplicationSession
a static singleton class and let it live in a subclass of Application
that you write.
精彩评论