Questions tagged [android-lifecycle]

Questions regarding the events forwarded by the system to components, during their lifetime, in an Android Application. Most components have a specific LifeCycle that is imposed upon them. This tag is not meant to be used alone: use with the [android-activity], [android-service] and [android-broadcastreceiver] tags.

Questions regarding the events forwarded by the system to components, during their lifetime, in an Android Application. Most components have a specific LifeCycle that is imposed upon them. This tag is not meant to be used alone: use with , , , or

Android Activity Lifecycle

Activity and Fragment Lifecycle Diagram

2414 questions
18
votes
7 answers

Differentiate between Android killing the app and user swiping it off on the recent apps list

I am working on a project, where while being on a specific Activity we show a local sticky notification. That should also be the case when the app is minimized. What I have to accomplish is to remove the local notification whenever the app is killed…
Nikola
  • 2,093
  • 3
  • 22
  • 43
18
votes
4 answers

Stop handler after the fragment has been destroyed

I have a Fragment which sets up a ListView and creates a Handler to update the Listview periodically. However, it looks like the Handler still runs after the Fragment has been destroyed. The following is the code. @Override public View…
18
votes
3 answers

Android - Keep previously added intent extra when going up to parent activity

Currently I am working with Android and I still have some troubles with understanding the Activity lifecycle. Let me show you my problem with an example: My App contains a Navigation Drawer which allows to use to switch between different Fragments.…
18
votes
2 answers

How to retrieve onSaveInstanceState() bundle in onResume()?

I am having a problem related to saving my Activity state. I searched and read about lots of questions here in SO but I couldn't get an answer for my question. I have an Activity A with 2 Fragments. The Activity A holds the data which is showed by…
Andres
  • 6,080
  • 13
  • 60
  • 110
17
votes
4 answers

ProcessLifecycleOwner not working after updating app compat to 1.4.1

I'm investigating a weird issue, where we changed the androidx.appcompat:appcompat from 1.3.1 to 1.4.1 and all of a sudden our LifecycleObservers observing process lifecycle stopped emitting any events. I'm also using…
17
votes
2 answers

How to solve "Cannot access androidx.activity.contextaware.ContextAware'"?

I'm building a simple application using LiveData and viewmodels but iam getting the following warning messages in my activity surrodning my activity some of the warning Cannot access 'androidx.activity.contextaware.ContextAware' which is a supertype…
a3adel
  • 1,223
  • 4
  • 15
  • 26
17
votes
2 answers

Android View Binding - Clear Binding in Fragment Lifecycle

Why is it important to clear the binding in onDestroyView when implementing Android View Binding in a Fragment? As the documentation shows, Use view binding in fragments, and the Android Architecture Components sample, the binding is initiated in…
17
votes
2 answers

NsdManager doesn't stop service discovery

In Android app that I'm currently developing, I want to connect do zero-config networks using NsdManager. I managed to run network service discovery and connect to the desired network, but after stopping discovery NsdManager thread is still…
17
votes
2 answers

When is fragment's onActivityResult called in respect to fragments lifecycle?

when i start Camera intent, i noticed onActivityResult is called before onResume in fragment lifecycle. I also noticed onActivityResult is called after onStart. But here's the strange part: i have variable fileUri == "some image path". This…
hendrix
  • 3,364
  • 8
  • 31
  • 46
17
votes
1 answer

Best architecture for a long running service on Android

I would appreciate some guidance on how to deal with OS killing a long run service. Business scenario: Application records a BTT track which may last for several hours. It can also show the track on map together with relevant statistics. The…
Luis
  • 11,978
  • 3
  • 27
  • 35
17
votes
5 answers

OnCreate() vs OnStart()

Possible Duplicate: Difference between onCreate() and onStart()? Android Activity Life Cycle - What are all these methods for? What is the difference between OnCreate and OnStart? My understanding is that OnCreate is only called the very first…
Josh Beckwith
  • 1,432
  • 3
  • 20
  • 38
16
votes
4 answers

Should we Use ViewModels to communicate between 2 different fragments or bundles in single activity App Architecture?

Scenario 1 - If we use ViewModels to communicate between fragments, then the ViewModel has to be created by activity reference and hence going to stay there in memory until the activity is destroyed. Scenario 2 - In master-detail flow ViewModel…
16
votes
5 answers

How to get LifecycleOwner in LifecycleObserver?

I need to get the LifecycleOwner in an LifecycleObserver to pass it into an ViewModel observer. This is my MainActivity, were I add the LifecycleObserver. public class MainActivity extends AppCompatActivity implements LifecycleOwner{ private…
16
votes
2 answers

RxJava resubscribe to event after activity restore

I'm still figuring out RxJava and using it to do some networking stuff with Retrofit 2. Been trying it our for a a couple days and like that the code looks more readable now but have come across an issue that I cant seem to figure a way around. I am…
source.rar
  • 8,002
  • 10
  • 50
  • 82
16
votes
8 answers

How can I know that onCreateView has been called from an outer class?

I'm really curious about how to determine (from an outer class) if a fragment's onCreateView() has already been called. I have searched for similar questions but found none. For instance, is fragment.isAdded() a good indicator? My first thought was…
natario
  • 24,954
  • 17
  • 88
  • 158