Questions tagged [lifecycleowner]
22 questions
17
votes
5 answers
Is it safe to pass LifeCycleOwner into RecyclerView.Adapter
Consider a layout data-bound to a viewModel. More specifically, the layout uses a layout variable for accessing this underlying viewModel. Whenever the binding is inflated, its viewModel and lifeCycleOwner are to be set. (Of course the viewModel…

lineage
- 792
- 1
- 8
- 20
9
votes
1 answer
Trying to create LifecycleCamera with destroyed lifecycle
I'm trying to make floating cameraview for my screen recorder application.
FloatingViewService.java
public class FloatingViewService extends LifecycleService implements CameraXConfig.Provider, LifecycleOwner {
private View mFloatingView;
…

Krunal Dholiya
- 91
- 3
3
votes
1 answer
Unable to access the Fragment View's LifecycleOwner when getView() is null i.e., before onCreateView() or after onDestroyView()
I've a fragment namely HomeFragment in my app. Following is the code for it:
import android.Manifest
import android.app.Activity
import android.app.AlertDialog
import android.content.Intent
import android.content.pm.PackageManager
import…

Apoorv Srivastava
- 65
- 1
- 5
2
votes
1 answer
requireActivity instead of requireContext in fragment
I am having a LiveData observer inside fragment, sometimes the code inside Observer{} throws error
Exception: java.lang.IllegalStateException: Fragment not attached to an activity.
at…

Rahul Matte
- 1,151
- 2
- 23
- 54
2
votes
0 answers
getLifecycle() returned null in ComponentActivity's constructor. Please make sure you are lazily constructing your Lifecycle
i get this Error "Caused by: java.lang.IllegalStateException: getLifecycle() returned null in ComponentActivity's constructor. Please make sure you are lazily constructing your Lifecycle"
after change
From Place Play Service
implementation…

user3788868
- 41
- 1
- 4
1
vote
2 answers
How can I track liveData subscription?
I have a problem with liveData. It doesn't update the fragment with the information. I think it unsubscribes from viewLifecycleOwner at some particular moment. Is there a way to track the subscription of liveData and see if it unsubscribes or not?…

Alex20280
- 97
- 6
1
vote
0 answers
FragmentContextWrapper cannot be cast to androidx.lifecycle.LifecycleOwner
I get the following error. Can you help me?
E/VRCameraViewCameraXImpl: Use case binding failed
java.lang.ClassCastException:
dagger.hilt.android.internal.managers.ViewComponentManager$FragmentContextWrapper
cannot be cast to…

Squall Huang
- 647
- 9
- 20
1
vote
2 answers
How to use Android LifecycleOwner in dialog
I want to use mvvm in Dialog but I don't know how to pass LifecycleOwner to observe
class CommonDialog(context: Context) : Dialog(context, R.style.AppMaskStatusTheme) {
private val viewBinding: DialogSportOrderBinding by lazy {…

GHH
- 1,713
- 1
- 8
- 21
1
vote
3 answers
Kotlin ViewModel onchange gets called multiple times when back from Fragment (using Lifecycle implementation)
I am working with the MVVM architecture.
The code
When I click a button, the method orderAction is triggered. It just posts an enum (further logic will be added).
ViewModel
class DashboardUserViewModel(application: Application) :…

Link 88
- 553
- 8
- 27
1
vote
1 answer
Lifecycleowner in a ViewModel - Android Studio
I'm trying to implement ViewModel in a app which get some data from Firestore using the FirestorepagingAdapter, and displays it in a recyclerview. I'm already getting all data and displayig it, but still not using ViewModel, it's all on the…

Fabiano31
- 29
- 3
1
vote
2 answers
java.lang.IllegalStateException: pb must not be null at TopHeadlinesFragment?
I am developing news app and I have implemented livedata with progress bar but I am getting following exception in my code
java.lang.IllegalStateException: pb must not be null
at…

Edgar
- 860
- 1
- 17
- 38
1
vote
1 answer
Observer in Fragment works but not in Activity
I created an Observer in a Fragment which works perfectly (it fires a toast when an Int increases), but when I try to move this code into the Activity, the observer doesn't seem to connect and it does not update when the LiveData changes.
Fragment…

Scamparelli
- 756
- 1
- 12
- 28
0
votes
0 answers
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 class is RemoteConfig based TextView. How could…

Taimoor Khan
- 541
- 4
- 20
0
votes
0 answers
What is the difference between lifecycleOwner and viewLifecycleOwner?
I've been studying on how to use Data Binding with Live Data. I understood how to setup data binding with layout and variable instructions in the Layout and how to link up the data binding variable in the Fragment/Activity code.
However, for my…

Amey079
- 131
- 7
0
votes
1 answer
For my interceptor I need use ifecycleOwner, I use the interceptor in Hilt module. But I dont know how get ifecycleOwner in Hilt Module?
@Module
@InstallIn(SingletonComponent::class)
object AppEntryModule {
private val client = OkHttpClient.Builder().apply {
addInterceptor(MyInterceptor( ????? ))
}.build()
@Provides
@Singleton
fun provideRetrofit(): Retrofit =
…

Dmitry Sergienko
- 85
- 6