0

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?

Community
  • 1
  • 1
Suraj Air
  • 2,063
  • 4
  • 22
  • 33
  • you can get info from this http://stackoverflow.com/questions/2139134/how-to-send-an-object-from-one-android-activity-to-another-using-intents – rkmax Sep 17 '11 at 17:40
  • please learn how to properly format your questions, see http://stackoverflow.com/editing-help – Jeff Atwood Sep 19 '11 at 06:35
  • Try the technique given here as an answer: http://stackoverflow.com/questions/4208886/using-the-android-application-class-to-persist-data – Christopher Souvey Sep 17 '11 at 17:39

1 Answers1

2

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.

Jon Willis
  • 6,993
  • 4
  • 43
  • 51
  • hey thnx for the asnwer ... But i got a new issue... while retrieving it throws RunTimeException.. appSession = (ApplicationSession)intent.getParcelableExtra("appSession"); – Suraj Air Sep 17 '11 at 19:02
  • I can't make sense of that without a stack trace or message – Jon Willis Sep 17 '11 at 19:06