-1

I searched for 2-3 days a solution to my problem, but i haven't found anyone who had a similar problem. Basically, my app is the "mobile version" of a web site, so I have to store temporally different account's informations, so I used a signleton class, call it "user". Yet while navigationg through certain 2 activities (in one I have an expandable list and in the the other a listview , like you have a cart (1st activity) to substitute its empty spaces with elements from the "shop" (2nd activity); so you go from one the other and viceversa several times). So, while going forward and backwork (via Intent()), suddenly the singleton gets re-initialized making the app crashing. The strange fact is that I do not get any error on the logcat, it only logs at a certain point that the singlotn call its init() method, making the app crashing immidiatley after. Another strange thing is that the first time that I implement this stuff it worked wiht no problem, yet now that I've implemented several other activities and added all the graphic elements (backgrounds for activities and list elements, many drawables, etc.) I get this problem (only doing the operations said before). (I don't know if this thing is relevant) My app uses the sliding menu by J. Feinstein (which is impemented in several acitivities, the one with the expandable list, e.g.) and the ActionBarSherlock (yet I use a custom action bar, so I inflate my own actionBar layout). Each activity has its sliding menu, created every time on onCreate() method of each activity.

Every part of code or log events that you need to help me, just ask and I'll put it here.

Thank you very much in advance for your help, I'm really stuck with this problem.

Axce
  • 1
  • 2

1 Answers1

0

I guess you want to have some "session" user.

I don't know the exact issue, but afaik the Android system may destroy static data when it is low in memory.

What you could do is store some values (user, timestamp) as Preference-values or as persistent data (file, db). Another way is of course to pass the required user data from one activity to another.

Carl K.
  • 457
  • 4
  • 16
  • Thank you Carl for your quick replay! Yes I need a "session" object, in fact I've read that a singleton extending Application class was perfect for that due to the fact that it stays alive until the app stays alive. Furthermore when I open the most important activities I call several webservices in order to have always updated data, and write/read always these data I thought it was slower that have them in a singleton class. Pass these data through activities I think it's really more complex than have them accessible from all activities, and have them centralized makes update them easier. – Axce Jul 20 '13 at 19:02
  • furthermore my partner, who develops the same app for iOS does not have this kind of problem, even if we have same singleton. Are singleton object managed differently from iOS and Android? – Axce Jul 20 '13 at 19:04
  • @Axce As I mentioned, the Android system may kill some resources outside your Activity. If you want to pass parameters between Activities, see here: http://stackoverflow.com/a/2091482/747906 – Carl K. Jul 21 '13 at 02:34