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
0
votes
0 answers

Notifications don't always dismiss when app is removed from recent tasks

It's intermittent and happens more often when I remove other applications as well. Hard to reproduce consistently. I have the builder set up as follows: if (Build.VERSION.SDK_INT >= 26) { CharSequence name = "Timers"; String description = "Timer…
0
votes
0 answers

Why is view null despite called in viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) in viewPager2's fragment?

We have a random crash on production in this class when accessing the binding at line 10 : class BulletinFragment : Fragment(R.layout.fragment_bulletins) { private val bulletinViewModel: BulletinsViewModel by viewModel() private val…
0
votes
0 answers

Need to restart app if its memory is trim or after some interval

The issue i am facing is my app memory gets cleared and app crashes while coming from background after long interval of time, to resolve this i just want to restart the app if its memory is trimmed or restart it if it goes in background for some…
Zubair Akber
  • 2,760
  • 13
  • 30
0
votes
0 answers

Behavior of FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_MULTIPLE_TASK

As per the documentation of FLAG_ACTIVITY_MULTIPLE_TASK: This flag is used to create a new task and launch an activity into it. This flag is always paired with either FLAG_ACTIVITY_NEW_DOCUMENT or FLAG_ACTIVITY_NEW_TASK. In both cases these flags…
ansh sachdeva
  • 1,220
  • 1
  • 15
  • 32
0
votes
0 answers

Navigates to second fragment again by pressing back button previous data exists

I have two fragments and one activity (Main Activity). Now when I go from fragment 1 to fragment 2 data in fragment 2 loads from api. But when I press back button, navigates to fragment 1 and again I go from fragment 1 to fragment 2 then the…
Harry
  • 154
  • 4
  • 15
0
votes
1 answer

androidx.lifecycle LifecycleObserver not working when disabling InitializationProvider

I have implemented LifecycleObserver in my Application class and it works without issue before. Now I needed to add WorkManager workers and inject them using hilt so I have this in my AndroidManifest.xml file for workers to work with…
Ralph
  • 550
  • 3
  • 10
  • 25
0
votes
0 answers

Why is lifecycleScope.launch not even working in the background?

First I gave the exerciseList a null value then inside the lifecycleScope I feched data from a preloaded database but why am I still getting null pointer exception on calling the exerciseList variable? private var exerciseList: ArrayList?…
0
votes
0 answers

dB noise meter (to record decibels) app not working when paused or minimized on mobile

I am using the dB meter app to record noise and show it in decibels with periodic intervals. And I am printing decibels for every second. The app is working fine when active but when I press square button on android (That is pause the app) the…
yellesh
  • 1
  • 1
0
votes
1 answer

Android. How to correct handle intent from BroadcastReceiver

I have activity and two fragments which opened in this activity (for example FragmentFirst, FragmentSecond). In my activity I register BroadcastReceiver. And when i receive any event (inside onReceive) I need to display the received text in the…
0
votes
1 answer

Android - How to correctly send an http request by CoroutineScope in a viewModel related to the lifecycle when exiting a fragment

I need to send an http request as soon as the user presses the back button and exits the fragment. I don't want to wait for a response from the server, I just need to shoot to the server. I can't do this in viewModelScope because it is related to…
0
votes
4 answers

Unsubscribe from Kotlin Flow without cancelling current scope

I am subscribing to a Kotlin SharedFlow of booleans within a repeatOnLifecycle block in Android. I want to subscribe until I receive the first true boolean and act on it. As soon as the first true boolean is received I need to unsubscribe and run…
0
votes
1 answer

Detach Fragment when Activity gets recreated

When the activity gets recreated due to config-change or memory issues when in stack (going back to the activity stack) the attached fragment gets recreated as well. In my case, the fragment cannot be recreated because it is linked to some…
0
votes
0 answers

Bundle doesnt loading when i return from activity

Hi I have an application and it has 2 fragments HomeFragment and ListFragment and also DetailActivity and UpdateActivity and AddActivity and when I go from fragment ListFragment to UpdateActivity | DetailActivity then HomeFragment saves the Bundle,…
0
votes
1 answer

How to catch the moment when the user leaves the app on Android?

We want to execute some code (reset app state) when the user leaves the app (via back or start button tap). At first we tried to override Activity.onPause() for this purpose. However, onPause is also called when the user returns from a child…
Pavel
  • 2,610
  • 3
  • 31
  • 50
0
votes
1 answer

How to pause a timer Object in Kotlin

I use this fragment of code in an activity to display a timer countdown: //SET COUNTDOWN TIMER in onCreate() //var tempo is a :Long number var textView = findViewById(R.id.countdownTimer) object :…