Tommehh
Tommehh

Reputation: 956

Lifecycle of items - android memory leak

I'm pretty new in developing android apps and I have a hard time to understand the app/activity/class lifecycle.

I have two activities: MainActivity and DetailActivity. Each one has it's own Fragments. There is a StatusController singleton between them, which implements the observer pattern.

I read about that android kills apps when it needs memory. So here are my questsions:

  1. Does it only kill the whole app or is it killing activities one by one?
  2. Is it possible that the activity behind a fragment gets killed but the fragment survives?
  3. Is there anywhere a documentation about what gets killed on memory leak?
  4. When do singleton classes get killed?

Upvotes: 1

Views: 469

Answers (1)

Abdul Waheed
Abdul Waheed

Reputation: 4678

Here are your answers:

  1. Does it only kill the whole app or is it killing activities one by one?

Android OS kills whole process rather killing an individual activity. Process kills mean your app will not running any more

  1. Is it possible that the activity behind a fragment gets killed but the fragment survives?

No it is not possible that acitivity is called but fragments survive because fragments are loaded over activity and fragment lifecycle is dependents on fragment.Once activity is destroyed fragment will no longer be visible anymore

  1. Is there anywhere a documentation about what gets killed on memory leak? When do singleton classes get killed?

    When you kill your app singleton classes will be killed. NOTE: If OS kills the process in which your app is running in that case all Singleton classes will be killed

NOTE: For memory leak documentation you may refer below mentioned link. https://mindorks.com/blog/detecting-and-fixing-memory-leaks-in-android

Upvotes: 1

Related Questions