user3220294
user3220294

Reputation: 53

Extending an Activity

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

Answers (2)

Larry
Larry

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

Endzeit
Endzeit

Reputation: 5474

If you want your programm to run in background even if the application isn't in foreground anymore you should use a Service instead of extending Activity.

Upvotes: 2

Related Questions