I know that, ViewModels should never keep a reference to a LifecycleOwner since it keeps a reference to a context and hence this causes a memory leak. But my question is, can I implement a LifecyclerOwner for ViewModel itself? with two valid callbacks, onCreate() triggered when view model's constructor is invoked and onDestroy() triggered when view model's onCleared() is invoked. Since LifecycleOwner is just an Java interface, I think this will not cause any memory leak. But to be on safer side, I'm asking this.
Can ViewModel implement LifecycleOwner?
731 Views Asked by Sourav Kannantha B At
0
There are 0 best solutions below
Related Questions in ANDROID
- Delay in loading Html Page(WebView) from assets folder in real android device
- MPAndroidChart method setWordWrapEnabled() not found
- Designing a 'new post' android activity
- Android :EditText inside ListView always update first item in the listview
- Android: Transferring Data via ContentIntent
- Wrong xml being inflated android
- AsyncTask Class
- Unable to receive extras in Android Intent
- Website zoomed out on Android default browser
- Square FloatingActionButton with Android Design Library
- Google Maps API Re-size
- Push toolbar content below statusbar
- Android FragmentPagerAdapter Circular listview
- Layout not shifting up when keyboard is open
- auDIO_OUTPUT_FLAG_FAST denied by client can't connect to localhost
Related Questions in VIEWMODEL
- MVVM: Updating ViewModel properties based on Model properties
- WPF use one ViewModel for multiple UserControls
- In MVC can ViewModels access service layer?
- How do I set a property in a ViewModel from another ViewModel in MVVM Light Toolkit
- View Model place in N Tier ASP .NET MVC application
- Cannot implicity List into IEnumerable
- Updating UI Bound to Dependant Properties
- MVC Viewmodel to display only model data
- Big giant view model for long scrolling page
- How to create a view model from a model interface in MVVM style?
- Unable to retrieve dynamic control generated from db - POST values (Model Binding)
- chained store source from another viewmodel
- How to load non model data in ExtJS viewmodel?
- Best practice for loading non model data in ExtJS
- How to wrap a button click event to the right ViewCell
Related Questions in ANDROID-LIFECYCLE
- Android version of NSNotificationCenter (event binding)
- Confused about this Android Activity life cycle scenario - OnCreate gets called whenever app goes back to foreground
- Are Application.ActivityLifecycleCallbacks synchronously called before the lifecycle methods in the Activity?
- Difference between finish() and finishAndRemoveTask()
- How to load xml resources to Activity field
- Android AlarmManager lifecycle not working
- Activity Conditional Flow
- Distinguish Android onDestroy events
- How to know when activity finished loading?
- Can't communicate with fragments in ViewPager after orientation change
- Differentiate between Android killing the app and user swiping it off on the recent apps list
- Android process in background - it must remain always alive - sometimes it has to play sounds
- When clicking back or home button, app goes back to activity's parent but onStart() isn't always called
- Android & AndroidJUnit4. How to handle & test indeterminate lifecycle loop error
- AppCompat Fragment lifecycle changed
Related Questions in LIFECYCLEOWNER
- Pass activity to LifecycleObserver
- Can ViewModel implement LifecycleOwner?
- Unable to access the Fragment View's LifecycleOwner when getView() is null i.e., before onCreateView() or after onDestroyView()
- View binding in traditional way using findViewbyId in LifecyclerObserver
- How can I track liveData subscription?
- FragmentContextWrapper cannot be cast to androidx.lifecycle.LifecycleOwner
- LifecycleObserver doesn't call onPause event on custom View - Android
- Lifecycleowner in a ViewModel - Android Studio
- LifecycleOwner migration in CustomView android
- Kotlin ViewModel onchange gets called multiple times when back from Fragment (using Lifecycle implementation)
- Android Workmanager
- getLifecycle() returned null in ComponentActivity's constructor. Please make sure you are lazily constructing your Lifecycle
- How to use Android LifecycleOwner in dialog
- java.lang.IllegalStateException: pb must not be null at TopHeadlinesFragment?
- requireActivity instead of requireContext in fragment
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?