When my app loads, I fill my android.app.Application with some data.
The app runs fine as I use it and all the data is available.
However, when I leave the app over night and look at it again the next
day, I receive NullPointerExceptions when attempting to use that same
data. I do not believe Application objects get garbage collected, so
I have no idea what is going on?
I also lose static objects in classes used by my Activity classes.
On Thu, Sep 23, 2010 at 9:03 AM, elubin <elubin1...@gmail.com> wrote: > However, when I leave the app over night and look at it again the next day, > I receive NullPointerExceptions when attempting to use that same data. I do > not believe Application objects get garbage collected, so I have no idea > what is going on?
> I also lose static objects in classes used by my Activity classes.
Hard to say without more details on how your app is structured, but it sounds like your app is being killed and restored, but you're not reloading / resetting your data. Perhaps the path through which you do this loading / initializing of variables is being skipped?
Logging all of the entry and exit points to your app you give you a better idea of what's happening and when.
--------------------------------------------------------------------------- ---------------------- TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago transit tracking app for Android-powered devices
That absolutely sounds like what is happening, but WHY would my app be
killed and restarted? You are correct, if it gets restarted on the
main window then i am not refilling my application data. I only fill
it on the login window. Do I misunderstand how application data is
supposed to work?
I have a login window, the user enters id/pw, i log in through web
service, store some data in my application object, and leave the user
at my main application window. i can then do any of my tasks, other
activities, etc.. using data from the application object.
when i click the icon and get back to the app the next day, it shows
me the main window again, right where i left it. however, the
application object is empty? what's the point of it if the JVM can
kill my app at any time and not store the application object?
help,
eric
On Sep 23, 12:59 pm, TreKing <treking...@gmail.com> wrote:
> On Thu, Sep 23, 2010 at 9:03 AM, elubin <elubin1...@gmail.com> wrote:
> > However, when I leave the app over night and look at it again the next day,
> > I receive NullPointerExceptions when attempting to use that same data. I do
> > not believe Application objects get garbage collected, so I have no idea
> > what is going on?
> > I also lose static objects in classes used by my Activity classes.
> Hard to say without more details on how your app is structured, but it
> sounds like your app is being killed and restored, but you're not reloading
> / resetting your data. Perhaps the path through which you do this loading /
> initializing of variables is being skipped?
> Logging all of the entry and exit points to your app you give you a better
> idea of what's happening and when.
> --------------------------------------------------------------------------- ----------------------
> TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
> transit tracking app for Android-powered devices
I think the lesson is that an Android application and android.app.Application are frequently mistakenly assumed to behave the same as an "application" on other operating systems.
On Thu, Sep 23, 2010 at 8:36 PM, elubin <elubin1...@gmail.com> wrote: > That absolutely sounds like what is happening, but WHY would my app be > killed and restarted?
I'm guessing because it's idle long enough and Android feels like killing it. If you're leaving your app alone over night, likely your phone is going to sleep, pausing your app. Left in this state long enough, it's not surprising that it would be killed eventually.
> You are correct, if it gets restarted on the main window then i am not > refilling my application data. I only fill it on the login window. Do I > misunderstand how application data is supposed to work?
Perhaps. As Dianne usually advises, you should scrap the Application idea and use a lazy-loading Singleton object to store your global / app-wide / static data as necessary.
> what's the point of it if the JVM can kill my app at any time and not > store the application object?
Well, I guess the point is to have the notion of an object that represents your app as a whole. But it's not the system's job to store and restore it's state - that's your job.
On Thu, Sep 23, 2010 at 11:56 PM, Frank Weiss <fewe...@gmail.com> wrote: > I think the lesson is that an Android application and > android.app.Application are frequently mistakenly assumed to behave the same > as an "application" on other operating systems.
Yes, this is an important point. OP, you must remember that leaving your app "open" does not mean it will never close as it does on Windows, for example. Android will kill it and restart it as need be - it only *appears* to have remained open since it restarts in the last activity you left it in.
--------------------------------------------------------------------------- ---------------------- TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago transit tracking app for Android-powered devices
> On Thu, Sep 23, 2010 at 8:36 PM, elubin <elubin1...@gmail.com> wrote:
> > That absolutely sounds like what is happening, but WHY would my app be
> > killed and restarted?
> I'm guessing because it's idle long enough and Android feels like killing
> it. If you're leaving your app alone over night, likely your phone is going
> to sleep, pausing your app. Left in this state long enough, it's not
> surprising that it would be killed eventually.
> > You are correct, if it gets restarted on the main window then i am not
> > refilling my application data. I only fill it on the login window. Do I
> > misunderstand how application data is supposed to work?
> Perhaps. As Dianne usually advises, you should scrap the Application idea
> and use a lazy-loading Singleton object to store your global / app-wide /
> static data as necessary.
> > what's the point of it if the JVM can kill my app at any time and not
> > store the application object?
> Well, I guess the point is to have the notion of an object that represents
> your app as a whole. But it's not the system's job to store and restore it's
> state - that's your job.
> On Thu, Sep 23, 2010 at 11:56 PM, Frank Weiss <fewe...@gmail.com> wrote:
> > I think the lesson is that an Android application and
> > android.app.Application are frequently mistakenly assumed to behave the same
> > as an "application" on other operating systems.
> Yes, this is an important point. OP, you must remember that leaving your app
> "open" does not mean it will never close as it does on Windows, for example.
> Android will kill it and restart it as need be - it only *appears* to have
> remained open since it restarts in the last activity you left it in.
> --------------------------------------------------------------------------- ----------------------
> TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
> transit tracking app for Android-powered devices