Questions tagged [android-architecture-lifecycle]

68 questions
3
votes
1 answer

Implementing a sidebar nav using android architecture components

With the new architecture components of android you can't use the default auto generated class navigation drawer class provided by android... why? because it extends from AppCompatActivity to provide the use of support.v7 lib for widgets like…
3
votes
1 answer

What is the difference between ViewModel and AndroidViewModel

For anyone having this question, As per Android Documentation, Since the ViewModel outlives specific activity and fragment instantiations, it should never reference a View, or any class that may hold a reference to the activity context. If the…
Rahul
  • 4,699
  • 5
  • 26
  • 38
2
votes
1 answer

How to inject dependencies in a SavedStateHandle-aware AndroidViewModel?

Assume a view model like this: public class FooViewModel extends AndroidViewModel { @Inject public FooViewModel(Application app, SavedStateHandle handle, Bar bar) { // ... } } I want to inject Bar using Dagger 2. I am developing on…
2
votes
1 answer

what does the ::MainViewModel mean when pass to the singleArgViewModelFactory

in kotlin coroutines lab smaple, https://codelabs.developers.google.com/codelabs/kotlin-coroutines/#6 it creates the viewModel by passing the MainViewModel.FACTORY(repository) val viewModel = ViewModelProviders .of(this,…
lannyf
  • 9,865
  • 12
  • 70
  • 152
2
votes
1 answer

Cannot trust current state of AAC lifecycle

Issue summary getLifecycle().getCurrentState() gave me wrong state. Environment (integrated library, OS, etc) compileSdkVersion : 27 targetSdkVersion : 27 support library : 27.1.1 Expected behavior onCreate() -> CREATED onStart() ->…
2
votes
1 answer

Room Livedata.observeforever not working after activity resumes

I have tested some test cases using the simple Room test code as below. "dao.getAll().observeForever()" does not work after main activity resumes. new words are inserted correctly but only observation does not work. If I use dao.getAll().observe(),…
2
votes
0 answers

Android Architecture Component - Prevent @OnLifecycleEvent when launching camera Intent

I implemented 2 LifecycleEvents Lifecycle.Event.ON_PAUSE and Lifecycle.Event.ON_START now these get triggered whenever I launch the camera Intent (which is logical in some way). Is there any way to prevent this?
2
votes
1 answer

How do I create a ViewModel for each page in a ViewPager?

I have a ViewPager, where I show multiple instances of PetFragment. To create a new instance of a PetFragment, I call PetFragment.newInstance(petId). I want a separate ViewModel instance for each petId. But ViewModelProvider.Factory#create() only…
2
votes
1 answer

Should my mvvm, livedata app cancel network requests when app is backgrounded?

Using Google's mvvm architecture components Github browser sample as a reference, how would one cancel a viewmodel hosted, live data observed, retrofit network request? :) Maybe I'm reading it wrong, but if network conditions are poor and requests…
2
votes
2 answers

Failed to resolve: android.arch.persistence.room:runtime: 1.0.0-alpha1

I am unable to compile the following gradle :- compile 'android.arch.persistence.room:runtime: 1.0.0-alpha1' Error Message :- Error:(26, 13) Failed to resolve: android.arch.persistence.room:runtime: 1.0.0-alpha1 Show in File Show in Project…
2
votes
1 answer

Strange LiveData behavior vs ObservableField

I have a problem with LiveData from new Android Architecture Components. I have used ObservableField before but wanted to try ACC. When I set up value by MutableLiveData.setValue 4 times in one method in Activity I get only one call onChange, when I…
2
votes
1 answer

Dagger : Why does dagger require a @inject constructor for an object that does't depend on another object

I think I'm missing something. I get this error: PostsVM cannot be provided without an @Inject constructor or from an @Provides-annotated method. Assume classes as follows : @Module public class AppModule { private final Application…
Relm
  • 7,923
  • 18
  • 66
  • 113
1
vote
1 answer

How do I use MVVM with bound service?

I have a bound service that is started as foreground service for handling exoplayer. Here is how my fragment handles the service - @AndroidEntryPoint class AudioPlayerFragment: Fragment() { private var binding: AudioPlayerFragmentBinding by…
1
vote
0 answers

how to initialise ViewModel in createFragment of FragmentStateAdapter?

I have a ExerciseDetailFragment that contains an ExerciseFragmentStatePagerAdapter to show a bunch of SupportUsFragmentCard. These cards can be swiped horizontally by the user. In my ExerciseFragmentStatePagerAdapter I have the following code: fun…
1
vote
1 answer

LiveData value is null after setting in viewModelScope

I have a viewmodel for a fragment with a search functionality. I made use of Coroutines to fetch from the API and then set the MediatorLiveData value with the result, although the list of objects are reflected on my RecyclerView. When I try to…