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.

Filter by
Sorted by
Tagged with
0 votes
1 answer
19 views

Cant launch new coroutine

I already have a lifecycleScope created in the MainActivity. When I try to create a new lifecycleScope, I get an error: Unresolved reference. None of the following candidates is applicable because of ...
PoltoranVlad's user avatar
1 vote
1 answer
31 views

(SOLVED)The Application Gives Error When Opened from Recent Applications

There is a SplashActivity in my application, the application is started with this activity. SplashActivity has a duration of 2.5 seconds, when this time is completed, HomeActivity opens. When the back ...
nataliaali's user avatar
0 votes
0 answers
15 views

Firebase data not updating when Flutter app is reopened from terminated state

Question: I'm facing an issue with my Flutter app where Firebase data doesn't update when the app is reopened from a terminated state (e.g., closed from the recent apps list). Here's a brief ...
AlluMl's user avatar
  • 3
0 votes
0 answers
39 views

How to avoid automatic invoking of paused activity when the transparent activity is triggered and finished its activity

In my current android app, I am using transparent activity for main and its has some of intent activities. My manifest file as follows, <?xml version="1.0" encoding="utf-8"?> ...
Kalai Selvi's user avatar
0 votes
0 answers
44 views

how to detect app lifecycle events on a jetpack compose composable

In order to detect app lifecycle events ( onPause, onStop, onResume ) in a jetpack compose composable i come up with this function : fun rememberLifecycleEvent(lifecycleOwner: LifecycleOwner = ...
joghm's user avatar
  • 569
0 votes
1 answer
21 views

How to close session in Fragment from click event that occurs in Activity

I've inherited a video playing app that I need to add analytics to. In my fragment I create the analytics object and this object then listens to and reports events and data. If the user clicks on ...
KoolKeith's user avatar
0 votes
0 answers
41 views

NullPointerException in getViewBinding

I have a fragment that uses viewbinding through eventhandlers. The eventhandlers are setup and taken down in onResume() and onPause(). In rare cases accessing the view through events results in a ...
mrbang's user avatar
  • 366
0 votes
1 answer
20 views

Why lifecycleScope is not waiting for viewmodelscope to finish?

I want a button to execute viewmodel's method before navigating to another fragment, but it seems that it is not waiting for all suspending functions to finish before changing screen: View.class ...
htafoya's user avatar
  • 18.3k
0 votes
0 answers
25 views

onStop is not being called when app is force killed

the ui was implemented using jetpack-compose. after i show BottomSheet somehow onStop is not being called when app is force killed from recent apps. but it is being called if there is no BottomSheet. ...
aligur's user avatar
  • 3,397
1 vote
0 answers
69 views

Opening custom chrome tab destroys the caller Activity in Android version prior to 12

I am using Android custom tabs for Authentication of my app. The custom tab is launched from the CustomTabLoginActivity. Once the user completes the sign up/login, the webpage gives a redirection with ...
Gopikrishnan S's user avatar
0 votes
0 answers
18 views

make BE API call when moving back from a fragment using onBackPressed()

i have a fragment A, B and I have moved from fragment A to B. now I am calling activity?.onBackPressedDispatcher?.onBackPressed() on fragment B to move back to fragment A. on fragment A I have BE API ...
BRDroid's user avatar
  • 3,962
0 votes
0 answers
23 views

Android Usage Events: APP_RESUMED twice

I am using the UsageEvents API to calculate daily foreground time of installed apps on an Android device https://developer.android.com/reference/android/app/usage/UsageEvents.Event What I am doing is ...
alexlipa's user avatar
  • 1,131
1 vote
0 answers
12 views

How to stop all native threads when Android app is backgrounded?

My video game is based on NativeActivity and has a lot of C++ threads. I'd like all those threads to pause like they do on iOS when my app is backgrounded. There are simply too many threads to chase ...
Bungles's user avatar
  • 1,985
0 votes
1 answer
215 views

When to use lifecycleScope.launch {}

I'm not clear on when and why we need to use lifecycleScope.launch {} I understand that this doesn't block the UI thread, but if you are doing UI work shouldn't you be doing it on the UIThread? What ...
user1743524's user avatar
0 votes
0 answers
55 views

Unresolved reference: ActivityLifecycleCallbacks

I am new in android development and stuck on building an existing project written in Java and Kotlin. I am upgrading the project by upgrading build system to Gradle 7 and compileSdkVersion 30. While ...
Soumen Mandal's user avatar
0 votes
0 answers
39 views

LifecycleOwners must call register before they are STARTED.gister while current state is STARTED

I am currently writing code in Android Studio to build a system that processes payments when a QR code is scanned. I have encountered an error saying "LifecycleOwners must call register before ...
K_Zio's user avatar
  • 1
0 votes
0 answers
18 views

What is the correct way and place to get parent view's width and height from within a custom view? [duplicate]

My custom view extends the AppCompatImageView class and it needs to know its parent view's dimensions. The following code is used: val w = (parent as ViewGroup).width val h = (parent as ViewGroup)....
Crocodile's user avatar
  • 5,724
0 votes
0 answers
47 views

How to mock lifecycleScope for Unit Test?

I`m writing unit tests for my lifecycleScope, but having trouble executing the tests. Can someone tell me how to mock lifecycleScope appropriately? sample code: class TestFragment : Fragment() { fun ...
刘路扬's user avatar
2 votes
1 answer
22 views

What happens when i call stopSelf in onDestroy method?

I have such a method implementation and I want to understand what will happen when this method is called. Could you give me a hint override fun onDestroy() { Timber.d("$this: onDestroy&...
Murad Akhmedov's user avatar
0 votes
0 answers
30 views

LifecycleOwner migration in CustomView android

I am upgrading lifeCycle components in an old project that uses lifeCycleRegistry. How can I update below code Below method is removed in new LifeCycleOwner interface. Lifecycle getLifecycle() Below ...
Taimoor Khan's user avatar
1 vote
1 answer
316 views

how to use Jetpack Compose in Service

I want to use Jetpack Compose to implement the floting window UI. But I got this error:java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from androidx.compose.ui.platform.ComposeView ...
Ting's user avatar
  • 31
0 votes
1 answer
54 views

How do apps like BUMBLE know as soon as the user disables LOCATION?

There are many apps which require location permission to operate. For example, BUMBLE. While using the app, if I disable location from the notification bar, it immediately knows, and degrades the ...
Shuvam Mandal's user avatar
0 votes
1 answer
175 views

Database_Impl not implemented - MVVM Room Kotlin Android

I'm new here, grateful to meet you all here. I have an error like this based on my Logcat. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.voidcreativestation.toko/com....
K La's user avatar
  • 1
0 votes
1 answer
112 views

How can I solve "Unreachable code" error in my kotlin project?

SplashActivity.kt @AndroidEntryPoint @SuppressLint("CustomSplashScreen") class SplashActivity : ComponentActivity() { private val viewModel: SplashScreenViewModel by ...
NewPartizal's user avatar
0 votes
1 answer
42 views

Vue3/Capacitor/Ionic ondestroy lifecycle hook?

I'm creating an app using Vue3\Capacitor\Ionic. One of the tests I've made is to catch the app being shutdown. I just want to send this event to my backend so that it can clean up the db for this ...
Wyn's user avatar
  • 97
1 vote
0 answers
144 views

ViewTreeLifecycleOwner not found when dismissing from BottomSheetDialogFragment for ComposeView

I have a ComposeView for a particular view that is within an XML layout for a view holder. This is shown as a list of items in a fragment. On this screen, when a BottomSheetDialogFragment shows, then ...
SmallGrammer's user avatar
0 votes
1 answer
35 views

Should Child Fragments get referenced in the ViewModel or the Parent Fragment

I have the below layout -MainActivity -ParentFragment -MaterialButtonToggleGroup -ChildFragmentA -RecyclerView -ChildFragmentB -RecyclerView When I press a ...
Lance Samaria's user avatar
0 votes
2 answers
190 views

ActivityResultLauncher not re-registered after Fragment recreated

I have a fragment where I am using DefaultLifecycleObserver to handle launching a file chooser and getting content (via a uri). The first time my fragment is created in the activity lifecycle, the ...
Daniel Bank's user avatar
  • 3,611
0 votes
1 answer
529 views

Show App Open Ads only on'cold start ' - openigng app from device home screen app icon

I have an app with Splash Screen and App Open Ads. Currently App Open Ads are showing three ways, when user - 1st one: opening app clicking app icon - Like this: App icon click > splash screen > ...
user3137451's user avatar
0 votes
1 answer
27 views

Dagger injected singleton is reverting to default value when OS initiates process death

I just want to understand if this (title) is normal behavior or if I have implemented dagger injection incorrectly? The steps I am taking to reproduce this bug is background app terminate process ...
Gil Ong's user avatar
  • 67
0 votes
0 answers
97 views

MainActivity onCreate called twice in TargetSDK 33 and minSDK is 24

I am trying to understand why Main launcher activity is launched twice as soon as I install the application for the first time. I Just created empty activity and added activity life cycle logs. Any ...
kavie's user avatar
  • 2,154
1 vote
0 answers
231 views

Duplicate Class Error while using android.lifecycle version 2.6.1

When using the following android lifecycle dependencies: // ViewModel implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" // ViewModel ...
Mauricio Benjamin Mossi's user avatar
0 votes
0 answers
62 views

Is there a way to inject UseCase in ViewModel created with ViewModelProvider and custom LifecycleOwner?

I am creating system Android application. I don't have activity, only the service. I created my custom class to inflate view and to show it. I want to access ViewModel in that class. ViewModel should ...
Lola's user avatar
  • 1
0 votes
1 answer
40 views

Android how to determine user kills the app

After review many questions on satck overflow I know that onDestroy() only called when system kills the app and the function of isFinishing(). But is there any function like onDestroy() that let me ...
Harvey Xie's user avatar
0 votes
0 answers
45 views

Activity gets restarted after Biometric Authentication

val promptInfo = BiometricPrompt.PromptInfo.Builder() .setTitle("Biometric authentication") .setSubtitle("Verify using your biometric ...
Divesh's user avatar
  • 112
0 votes
0 answers
38 views

Collect flow only when Tab is visible android

When we have a TabLayout, each Fragment is going between onResume and onPause when it is visible and invisible accordingly. If we swipe more than 2-3 fragments away, then onDestroy is called. However, ...
james04's user avatar
  • 1,640
0 votes
1 answer
282 views

Collect from only between onResume and onPause Android

I have a HomeActivity with a TabLayout and 3 fragments. OneFragment, TwoFragment, ThreeFragment. In the HomeViewmodel i have a StateFlow which takes a value and OneFragment collects the result and ...
james04's user avatar
  • 1,640
0 votes
2 answers
128 views

onActivityCreated() is deprecated and I think it's causing my save contact feature to not work, but no idea how to fix it

I have been working on an Android app for a project and have to make a communications button that basically just works as a contacts app. So I followed a tutorial on how to make it, but he uses some ...
epicobadah's user avatar
0 votes
1 answer
37 views

Coroutine initializes one lateinit var but not the other

I am making two retrofit calls from lifecycle scope. These two calls use async and await to get data from api. Code : package com.example.retrofittodo import androidx.appcompat.app.AppCompatActivity ...
Siddharth Manthan's user avatar
9 votes
1 answer
626 views

Compiler error only in Android Studio but not in Gradle build: abstract base class member getLifecycle() not implemented

In my Android project in AndroidStudio a class (named MyService below), which extends LifecycleService, is marked with the following error message: Class 'MyService' is not abstract and does not ...
user2808624's user avatar
  • 2,502
0 votes
1 answer
168 views

Jetpack Lifecycle: Fragment's View Lifecycle never reaching CREATED state, never destroyed

Problem I recently noticed one case when in an Android app, the following exception is triggered: java.lang.IllegalArgumentException: Cannot add the same observer with different lifecycles It happens ...
Vince's user avatar
  • 1,570
0 votes
1 answer
139 views

How can I define lifecycleaware coroutinescope for activity or application in composable function?

Let says I have splash Screen: @Composable fun SplashScreen(viewModel: SplashViewModel = hiltViewModel()) { val lifecycleOwner = LocalLifecycleOwner.current val externalsomeScope="?&...
yardımcı Etis's user avatar
0 votes
1 answer
293 views

Pressing back button in Android MainActivity does not destroy the activity anymore. Is it a new feature?

When I press the back button in MainActivity the home screen is shown, however onDestroy is not being called. Is it a new feature? Using Emulator Pixel 3A in API 33 arm 64-v8a. The same happens ...
Bekzad Nasirakhunov's user avatar
0 votes
0 answers
27 views

Android app crashing after 3 rotations. JAVA/ANDROID

Im not sure what i could have done to make it consistently crash after 3 rotations. I was debugging and profiling the app while testing the crash and not once did the debug console tell me anything ...
Kooshe's user avatar
  • 1
0 votes
0 answers
15 views

Is AccessibilityService's lifecycle is more than Application's lifecycle?

Suppose I initialize Firebase AppCheck in the Application class onCreate method. Can I access it in AccessibilityService or it may get destroyed? Also, if it may get destroyed, where should I ...
Jazib Khan's user avatar
0 votes
0 answers
13 views

Andorid click event triggers the backstack actitivty

I'm dealing with unexpected situation. There is an activity(Activity A) triggers another activity(Activity B). and Activity B triggers another Activity (Activity C). All activities are half screen ...
Yunus Emre KÜTÜK's user avatar
4 votes
2 answers
1k views

Duplicate class error caused by 'androidx.lifecycle:lifecycle-runtime-compose' implementation

Error - Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules jetified-kotlin-stdlib-1.8.10 (org.jetbrains.kotlin:kotlin-stdlib:1.8.10) and jetified-kotlin-stdlib-jdk8-1.7.10 (org....
Vaishnav Kanhirathingal's user avatar
0 votes
1 answer
422 views

Android java.lang.IllegalStateException: Method addObserver must be called on the main thread

In my recent app version, I am seeing a lot of logs related to this issue: java.lang.IllegalStateException: Method addObserver must be called on the main thread androidx.lifecycle.LifecycleRegistry....
KsiAndroid's user avatar
0 votes
0 answers
22 views

NDK Global value lifecycle

In Android NDK, I use an audio synth engine, which takes a few seconds to initialize. Therefore, I want to use a global (legitimate use of singleton) variable alive as long as possible. Are there any ...
Kirsteins's user avatar
  • 27.1k
1 vote
1 answer
27 views

Launch activity recreating

I am initiating a 3rd party library which is further calling another library sometimes what happens is the main launcher activity is being destroyed and recreated i.e. their are two SDKs let's SDK1 ...
sourabh kaushik's user avatar

1
2 3 4 5
49