Reputation: 53
I am currently extending an Activity from a non "screen" class in android. I did this as I noticed that the OS was killing non-activity classes and this was causing me a few problems when my app was running for a long time. I am just wondering if this is bad practice/is likely to cause me problems further down the line? Thanks you all for your responses.
Upvotes: 1
Views: 96
Reputation: 394
If you create an object in an Activity Class A, then navigate to Activity B, remember that the OS may destroy Activity A at any time. In fact, there is a debug option to automatically kill activities when you navigate to another (for testing).
Once Activity A has been destroyed, any objects created will be destroyed and their memory reclaimed. If you want objects to remain after you leave Activity A, you need to save them in the Application class or perhaps a singleton.
Upvotes: 2