Questions tagged [android-architecture-lifecycle]

68 questions
31
votes
6 answers

Share ViewModel between fragments that are in different Activity

I have a ViewModel named SharedViewModel: public class SharedViewModel extends ViewModel { private final MutableLiveData selected = new MutableLiveData<>(); public void select(T item) { selected.setValue(item); } …
25
votes
7 answers

How can I perform LiveData transformations on a background thread?

I have a need to transform one type of data, returned by a LiveData object, into another form on a background thread to prevent UI lag. In my specific case, I have: MyDBRow objects (POJOs consisting of primitive longs and Strings); a Room DAO…
19
votes
3 answers

AppCompatActivity not implementing LifecycleOwner

I am using Android Support Library 26.1.0. These are the dependencies in the app module: implementation "android.arch.lifecycle:runtime:1.0.0" implementation "android.arch.lifecycle:extensions:1.0.0-beta1" implementation…
17
votes
2 answers

How to setSupportActionBar in a view that extends LifecycleActivity

I had an Activity that extended AppCompactActivity, and in onCreate method I setted the Toolbar using setSupportActionBar method in the usual way: public class StepMasterActivity extends AppCompatActivity{ @Override protected void…
16
votes
2 answers

Pre-launch-report failures due to missing methods (in com.google.android.apps.mtaas.crawler-1/base.apk)

Since recently my app started to contain strange error messages in the pre-launch reports (automatically generated after upload to the Play store). These reports contain exceptions such as the following: Exception java.lang.NoSuchMethodError: No…
14
votes
4 answers

ViewModel refetches data when fragment is recreated

I am using Bottom Navigation with Navigation Architecture Component. When the user navigates from one item to another(via Bottom navigation) and back again view model call repository function to fetch data again. So if the user goes back and forth…
11
votes
3 answers

java.lang.IllegalStateException: Cancel call cannot happen without a maybeRun

I am trying to test a simple ViewModel with Robolectric. Here's my ViewModel GreetingsViewModel.kt @FlowPreview @ExperimentalCoroutinesApi class GreetingsViewModel : ViewModel() { private val greetingsChannel =…
10
votes
7 answers

How can I add unit test for android architecture components life cycle event?

I tried to add a unit test for my function which supports architecture components lifecycle event. To support lifecycle event, I added the @OnLifecycleEvent annotation for my function which I want to do something when that event occurred.…
9
votes
2 answers

Cant find class DiffCallback in Android Architecture component 1.1.1:

Recently I updated android.arch support library version in gradle file // ViewModel and LiveData implementation "android.arch.lifecycle:extensions:1.1.1" // alternatively, just ViewModel implementation…
8
votes
3 answers

AndroidViewModel - Making duplicate calls doesn't return data in observe function

My question is related to ViewModel second time returns null wherein I am not getting callback inobserve function if I make a repeated call to server. Following is the code I am using - @Singleton public class NetworkInformationViewModel extends…
8
votes
3 answers

What is the difference between LiveData and LifecycleObserver

I have read the document about Life Cycle and Live Data in the android official documentation. I know the class implemented LifeCycleObserver and make the location listener closed or open automatically. I also know the live data can make it active…
7
votes
2 answers

Do I need to call removeObserver for lifecycle, upon its onDestroy() event?

This is a very simple question: Background I'm using the relatively new Lifecycle class (part of the android architecture components libraries) to handle some events of the Activity/Fragment in an easier way. This is how you use it for handling…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
7
votes
2 answers

Android LiveData - switchMap is not triggered on second update

I have a LiveData object that depends on another LiveData. As I understand, Transformations.switchMap should allow to chain them. But switchMap handler is triggered only once and it doesn't react on further updates. If instead I use observe on the…
6
votes
2 answers

Does event wrapper pattern replace the use of SingleLiveEvent?

I'm adopting MVVM to my Android apps recently. In order to solve the problems underlying with the lifecycle of an app, Google had released LiveData. The usage of LiveData has different scenarios, as pointed out in the medium article wrote by Jose…
6
votes
0 answers

ViewModel, Room, LiveData, RecyclerView filter data

I'm working on an inventory application based on Architecture components (ViewModel/Room/Livedata) and RecyclerView. The app based on the practise that Google recommends in Developer training book. Advanced Android Development Course - Working with…
1
2 3 4 5