Fixed
Status Update
Comments
il...@google.com <il...@google.com>
il...@google.com <il...@google.com> #2
ViewModels need to be cleared on Fragments that are being really destroyed, where "really destroyed" means that they are being destroyed without their state being saved, indicating that there's no chance they are going to be restored at a later time.
Unfortunately, isStateSaved(), despite its name, does double duty as a check on whether it is safe to do Fragment Transactions and is always true after onStop(), meaning it can be true even if the state has really not been saved, oddly enough.
We'll just not use isStateSaved() here and rely on a separate indicator for the "really destroyed" case.
Unfortunately, isStateSaved(), despite its name, does double duty as a check on whether it is safe to do Fragment Transactions and is always true after onStop(), meaning it can be true even if the state has really not been saved, oddly enough.
We'll just not use isStateSaved() here and rely on a separate indicator for the "really destroyed" case.
il...@google.com <il...@google.com>
lo...@gmail.com <lo...@gmail.com> #3
@ comment #2 Fixed in which version?
b9...@gmail.com <b9...@gmail.com> #5
We have to update compile SDK to 28 to adapt this fix?!
b9...@gmail.com <b9...@gmail.com> #7
When will 27.1.1 be released? It is a critical bug seriously.
yc...@gmail.com <yc...@gmail.com> #8
This also seems to have caused a side effect / bug where a ViewModel instance is recreated when its Activity is in the background when device is rotated.
il...@google.com <il...@google.com> #9
[Deleted User] <[Deleted User]> #10
Re #9
This issue I was referring to was only reproducible with 27.1.0 though. The one you were referring to was reported prior to 27.1.0 release. Anyway I'll report it as a separate issue. Thanks.
This issue I was referring to was only reproducible with 27.1.0 though. The one you were referring to was reported prior to 27.1.0 release. Anyway I'll report it as a separate issue. Thanks.
kk...@google.com <kk...@google.com> #11
This bug has been fixed in Support Library 27.1.1.
[Deleted User] <[Deleted User]> #12
The bug with ViewModel is probably fixed, but there is still an issue with loaders: https://issuetracker.google.com/issues/78095959
an...@gmail.com <an...@gmail.com> #13
This bug doesn't seem to be fixed in 27.1.1.. My application is currently crashing because Fragment's ViewModel doesn't get its #onCleared() method called.
I have all the latest stable versions of Android Studio, support libraries, architecture components libraries and so on.
Are you sure that the fix to this issue was included in 27.1.1? Or maybe in 28.0.0-alphaX?
I have all the latest stable versions of Android Studio, support libraries, architecture components libraries and so on.
Are you sure that the fix to this issue was included in 27.1.1? Or maybe in 28.0.0-alphaX?
il...@google.com <il...@google.com> #14
Re #13 - The original issue as demonstrated by the sample projects attached has been fixed in 27.1.1.
You could certainly have an issue with similar symptoms but with a different root cause - if you're able to reproduce an issue even with the latest 28.0.0-alpha3, please file a new bug with a sample project that reproduces your issue.
You could certainly have an issue with similar symptoms but with a different root cause - if you're able to reproduce an issue even with the latest 28.0.0-alpha3, please file a new bug with a sample project that reproduces your issue.
al...@gmail.com <al...@gmail.com> #15
The following scenario is still unfixed:
Have Don't keep activities enabled.
Start the app.
Push home button.
On 27.0.2 I have the following output at logcat:
V/ViewModelFirst: Created
V/ViewModelFirst: onCleared
V/FragmentFirst: onDestroy
V/MainActivity: onDestroy
Which totally correct.
But on 27.1.1 till 28.0.0-alpha3 I have the following output at logcat:
V/ViewModelFirst: Created
V/FragmentFirst: onDestroy
V/MainActivity: onDestroy
As we can see activity and fragment was destroyed but viewModel was not notified with onCleared.
I suspect that in case if the Don't keep activities will be disabled and the app at background will be naturally unloaded by Android at some moment of time the viewModel.onCleared() will not be called which is very sad.
Have Don't keep activities enabled.
Start the app.
Push home button.
On 27.0.2 I have the following output at logcat:
V/ViewModelFirst: Created
V/ViewModelFirst: onCleared
V/FragmentFirst: onDestroy
V/MainActivity: onDestroy
Which totally correct.
But on 27.1.1 till 28.0.0-alpha3 I have the following output at logcat:
V/ViewModelFirst: Created
V/FragmentFirst: onDestroy
V/MainActivity: onDestroy
As we can see activity and fragment was destroyed but viewModel was not notified with onCleared.
I suspect that in case if the Don't keep activities will be disabled and the app at background will be naturally unloaded by Android at some moment of time the viewModel.onCleared() will not be called which is very sad.
lb...@gmail.com <lb...@gmail.com> #17
@15 You should open a new thread. Once Google closes an issue , there is a much smaller chance they ever read what you've written in it, and it happens a lot, sadly
al...@gmail.com <al...@gmail.com> #18
3g...@gmail.com <3g...@gmail.com> #20
file sdcard encrypt....
[Deleted User] <[Deleted User]> #21
Common
Description
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation "android.arch.lifecycle:runtime:1.1.0"
implementation "android.arch.lifecycle:extensions:1.1.0"
implementation "android.arch.lifecycle:common-java8:1.1.0"
Version used: 27.1.0
Theme used: N/A
Devices/Android versions reproduced on: Emulator 24
- Relevant code to trigger the issue.
Make an Activity that contains a Fragment.
Make the Activity use a ViewModel, and make the Fragment also use a ViewModel.
Start the Activity and press back.
The Activity's ViewModel's onCleared method is called.
With AppCompat 27.0.2, the Fragment's ViewModel's onCleared method is called (as it should)
With AppCompat 27.1.0, the Fragment's ViewModel's onCleared method is not called (incorrect).
See the attached project that shows the issue.
With 27.0.2, the logs read:
---------------------------
org.jraf.android.viewmodelproblem.MainActivity: onCreate
org.jraf.android.viewmodelproblem.MainActivityViewModel: constructor
org.jraf.android.viewmodelproblem.MainFragment: onCreate
org.jraf.android.viewmodelproblem.MainFragmentViewModel: constructor
[back is pressed]
org.jraf.android.viewmodelproblem.MainActivity: onDestroy
org.jraf.android.viewmodelproblem.MainActivityViewModel: onCleared
org.jraf.android.viewmodelproblem.MainFragmentViewModel: onCleared
org.jraf.android.viewmodelproblem.MainFragment: onDestroy
With 27.1.0, the logs read:
---------------------------
org.jraf.android.viewmodelproblem.MainActivity: onCreate
org.jraf.android.viewmodelproblem.MainActivityViewModel: constructor
org.jraf.android.viewmodelproblem.MainFragment: onCreate
org.jraf.android.viewmodelproblem.MainFragmentViewModel: constructor
[back is pressed]
org.jraf.android.viewmodelproblem.MainActivity: onDestroy
org.jraf.android.viewmodelproblem.MainActivityViewModel: onCleared
org.jraf.android.viewmodelproblem.MainFragment: onDestroy
This seems to happen because of line 1645 of Fragment, this test:
if (mViewModelStore != null && !mHost.mFragmentManager.isStateSaved()) {
is always false because mHost.mFragmentManager.isStateSaved() is true.