Assigned
Status Update
Comments
jm...@google.com <jm...@google.com> #2
After looking more into this issue, ViewModels are persisted using retained fragments. After adding retained fragments to the sample app, we can observe that retained fragments are not able to survive landscape lock and unlock scenario either.
jm...@google.com <jm...@google.com>
ar...@gmail.com <ar...@gmail.com> #3
Hey, currently I can't reproduce your issue.
Link you provided doesn't work, in my simple test project I don't observe described issue.
Could you please say reupload your project somewhere else?
Could you please say what kind of lockscreen, do you use? (it may effect issue)
Could you reproduce this behavior on other devices?
Link you provided doesn't work, in my simple test project I don't observe described issue.
Could you please say reupload your project somewhere else?
Could you please say what kind of lockscreen, do you use? (it may effect issue)
Could you reproduce this behavior on other devices?
h....@gmail.com <h....@gmail.com> #4
Hey,
Sorry about the repo link, here is the public one:https://github.com/karmazindmitriy/viewmodelscoping , git@github.com:karmazindmitriy/viewmodelscoping.git
Tested on:
1. Device: NEXUS 5X, API level: 24, lock method: PIN / PATTERN / SWIPE / PASSWORD. Can reproduce by unlocking with any of the unlocking methods. Can also reproduce by unlocking with fingerprint.
2. Device: NEXUS 5X, API level: 27, lock method: PIN / PATTERN / PASSWORD . Can reproduce only when unlocking the device with a fingerprint. Unlocking with PIN / PATTERN / PASSWORD works fine.
3. Device: Pixel, API level: 27, lock method: PIN (haven't tested other) + fingerprint. Can reproduce only when unlocking the device with a fingerprint. Unlocking with PIN / PATTERN / PASSWORD works fine.
Hope this is helpful, please let me know if you need any other info.
Sorry about the repo link, here is the public one:
Tested on:
1. Device: NEXUS 5X, API level: 24, lock method: PIN / PATTERN / SWIPE / PASSWORD. Can reproduce by unlocking with any of the unlocking methods. Can also reproduce by unlocking with fingerprint.
2. Device: NEXUS 5X, API level: 27, lock method: PIN / PATTERN / PASSWORD . Can reproduce only when unlocking the device with a fingerprint. Unlocking with PIN / PATTERN / PASSWORD works fine.
3. Device: Pixel, API level: 27, lock method: PIN (haven't tested other) + fingerprint. Can reproduce only when unlocking the device with a fingerprint. Unlocking with PIN / PATTERN / PASSWORD works fine.
Hope this is helpful, please let me know if you need any other info.
mi...@gmail.com <mi...@gmail.com> #5
Thanks, yep, I was able to reproduce it.
ra...@gmail.com <ra...@gmail.com> #6
Oh, another instance when platform doesn't call onSaveInstanceState, but calls onStop and onRetainNonConfiguration, so fragments are confused, we are going to fix fragments so they work around this behavior.
cr...@gmail.com <cr...@gmail.com> #7
Are you referring to the first `onStop` that happens right after unlock (line 12 in screenshot)?
go...@gmail.com <go...@gmail.com> #8
yep
gu...@gmail.com <gu...@gmail.com> #9
Hello, I Have notice the same issue when using ViewModel, here is the scenario:
1) open ActivityA
-gets ViewModel with reference: TestViewModel@e71fab8
2) rotate device
-gets ViewModel with reference: TestViewModel@e71fab8
3) open ActivityB
4) rotate device
5) press back (finish Activity B)
6) Activity A comes back from stack
-gets ViewModel with reference: TestViewModel@260072e
I have tested with two kinds of ViewModel, with factory and default creation method:
ViewModelProviders.of(this).get(TestViewModel::class.java)
ViewModelProviders.of(this, factory).get(DashboardViewModel::class.java)
Both Activities extends AppCompatActivity class.
I have made some research and find case when this issue do not happend:
1) open ActivityA (vertical)
-gets ViewModel with reference: TestViewModel@e71fab8
2) rotate device (horizontal)
-gets ViewModel with reference: TestViewModel@e71fab8
3) open ActivityB (horizontal)
4) rotate device (vertical)
5) rotate device (horizontal)
6) press back (finish Activity B)
7) Activity A comes back from stack (horizontal)
-gets ViewModel with reference: TestViewModel@e71fab8
So when I rotate device twice on Activity B and press back the Activity A do not recreate ViewModel, mayeby it is becouse it has the same orientation as befor putting it in activities stack.
1) open ActivityA
-gets ViewModel with reference: TestViewModel@e71fab8
2) rotate device
-gets ViewModel with reference: TestViewModel@e71fab8
3) open ActivityB
4) rotate device
5) press back (finish Activity B)
6) Activity A comes back from stack
-gets ViewModel with reference: TestViewModel@260072e
I have tested with two kinds of ViewModel, with factory and default creation method:
ViewModelProviders.of(this).get(TestViewModel::class.java)
ViewModelProviders.of(this, factory).get(DashboardViewModel::class.java)
Both Activities extends AppCompatActivity class.
I have made some research and find case when this issue do not happend:
1) open ActivityA (vertical)
-gets ViewModel with reference: TestViewModel@e71fab8
2) rotate device (horizontal)
-gets ViewModel with reference: TestViewModel@e71fab8
3) open ActivityB (horizontal)
4) rotate device (vertical)
5) rotate device (horizontal)
6) press back (finish Activity B)
7) Activity A comes back from stack (horizontal)
-gets ViewModel with reference: TestViewModel@e71fab8
So when I rotate device twice on Activity B and press back the Activity A do not recreate ViewModel, mayeby it is becouse it has the same orientation as befor putting it in activities stack.
mo...@gmail.com <mo...@gmail.com> #10
This behavior is due to FragmentActivity.onDestroy() calling into mViewModelStore.clear() if mRetaining is false. This is the case when the device is rotated and the affected activity is in the background (and probably in other conditions outlined above as well). It is not the case if the configuration changes when the activity is in the front.
Since the view model store has ben cleared, a new view model will be created for the affected activity after a configuration change in the background.
The behavior can be observed easily using a break point in ViewModelStore.clear()
Since the view model store has ben cleared, a new view model will be created for the affected activity after a configuration change in the background.
The behavior can be observed easily using a break point in ViewModelStore.clear()
[Deleted User] <[Deleted User]> #11
Easy way to detect the condition from within onDestroy() on your own activity:
override fun onDestroy() {
val current = ViewModelProviders.of(this).get(VM::class.java)
super.onDestroy()
val fresh = ViewModelProviders.of(this).get(VM::class.java)
if (current != fresh) {
Log.e("Main", "View model has been destroyed")
}
}
override fun onDestroy() {
val current = ViewModelProviders.of(this).get(VM::class.java)
super.onDestroy()
val fresh = ViewModelProviders.of(this).get(VM::class.java)
if (current != fresh) {
Log.e("Main", "View model has been destroyed")
}
}
ak...@gmail.com <ak...@gmail.com> #12
And a dirty workaround:
override fun onDestroy() {
val current = ViewModelProviders.of(this).get(VM::class.java)
super.onDestroy()
@Suppress("UNCHECKED_CAST")
val fresh = ViewModelProviders.of(this, object : ViewModelProvider.Factory{
override fun <T : ViewModel?> create(modelClass: Class<T>) = current as T
}).get(VM::class.java)
if (current != fresh) {
Log.e("Main", "View model destroyed!")
}
}
override fun onDestroy() {
val current = ViewModelProviders.of(this).get(VM::class.java)
super.onDestroy()
@Suppress("UNCHECKED_CAST")
val fresh = ViewModelProviders.of(this, object : ViewModelProvider.Factory{
override fun <T : ViewModel?> create(modelClass: Class<T>) = current as T
}).get(VM::class.java)
if (current != fresh) {
Log.e("Main", "View model destroyed!")
}
}
na...@gmail.com <na...@gmail.com> #13
It's happening also after entering to multi-window mode
xi...@google.com <xi...@google.com> #14
Somebody put my issue https://issuetracker.google.com/issues/78095959 as a duplicate of this one. I would like to clarify, if this is really the case and if the issue that I reported will also be taken into account when fixing this issue.
Quote #6:
"Oh, another instance when platform doesn't call onSaveInstanceState, but calls onStop and onRetainNonConfiguration, so fragments are confused, we are going to fix fragments so they work around this behavior."
In the case which I presented, onSaveInstanceState IS called. But after that the activity is destroyed, so are the fragments. But ViewModel is not being cleared. There is a condition which skips clearing ViewModel after state is saved:
/**
* Called when the fragment is no longer in use. This is called
* after {@link #onStop()} and before {@link #onDetach()}.
*/
@CallSuper
public void onDestroy() {
mCalled = true;
// Use mStateSaved instead of isStateSaved() since we're past onStop()
if (mViewModelStore != null && !mHost.mFragmentManager.mStateSaved) {
mViewModelStore.clear();
}
}
But for fragments that are destroyed, loaders must be reset, like it happens in case of activity. I think the right condition for loader lifecycle to work correctly should be something like this:
if (mViewModelStore != null) {
// Do not reset loaders on activity rotation
final Activity activity = getActivity();
if (activity != null && !activity.isChangingConfigurations()) {
fragment.mViewModelStore.clear();
}
}
So loaders are always reset in Fragment.onDestroy(), unless the activity is rotated. I think this is also applicable to ViewModel.
Quote #6:
"Oh, another instance when platform doesn't call onSaveInstanceState, but calls onStop and onRetainNonConfiguration, so fragments are confused, we are going to fix fragments so they work around this behavior."
In the case which I presented, onSaveInstanceState IS called. But after that the activity is destroyed, so are the fragments. But ViewModel is not being cleared. There is a condition which skips clearing ViewModel after state is saved:
/**
* Called when the fragment is no longer in use. This is called
* after {@link #onStop()} and before {@link #onDetach()}.
*/
@CallSuper
public void onDestroy() {
mCalled = true;
// Use mStateSaved instead of isStateSaved() since we're past onStop()
if (mViewModelStore != null && !mHost.mFragmentManager.mStateSaved) {
mViewModelStore.clear();
}
}
But for fragments that are destroyed, loaders must be reset, like it happens in case of activity. I think the right condition for loader lifecycle to work correctly should be something like this:
if (mViewModelStore != null) {
// Do not reset loaders on activity rotation
final Activity activity = getActivity();
if (activity != null && !activity.isChangingConfigurations()) {
fragment.mViewModelStore.clear();
}
}
So loaders are always reset in Fragment.onDestroy(), unless the activity is rotated. I think this is also applicable to ViewModel.
[Deleted User] <[Deleted User]> #15
Was about to report this issue. I too am observing the same issue - exactly as do...@gmail.com https://issuetracker.google.com/issues/73644080#comment9 describes it. I also noted that if the ViewModel is instantiated with a Fragment - ie: mViewModel = ViewModelProviders.of(<Fragment>).get(TestViewModel.class); - the ViewModel will always get the same instance back - even in the above described scenarios.
I found a sample project on GitHub where the issue is easily reproduced as well:https://github.com/jshvarts/SimpleViewModel
I found a sample project on GitHub where the issue is easily reproduced as well:
ed...@gmail.com <ed...@gmail.com> #16
- I have a temporary solution that we have implemented using retained fragments to hold the ViewModel.
See:https://bitbucket.org/sajeevmadu/viewmodeltest for the solution.
See:https://issuetracker.google.com/issues/78788599
for a video of the issue.
See:
See:
for a video of the issue.
ma...@gmail.com <ma...@gmail.com> #17
This is fixed internally and will be available in future releases of the fragment dependency.
[Deleted User] <[Deleted User]> #18
when and which version will this fix be included?
oe...@googlemail.com <oe...@googlemail.com> #19
The fix is available in 28.0.0-alpha3 and AndroidX 1.0.0-alpha3
ap...@paymentus.com <ap...@paymentus.com> #22
For anyone still following this thread: tried with 28.0.0-alpha3 and AndroidX 1.0.0-alpha3 and it doesn't happen anymore.
du...@google.com <du...@google.com> #23
Sadly moving to AndroidX is a huge issue for large projects. It makes so many build errors. I hope it gets fixed in future version of Android Studio
nj...@gmail.com <nj...@gmail.com> #24
If you're comfortable with alpha releases of the support library, you can raise your target to 28 and use 28.0.0-alpha3.
du...@google.com <du...@google.com> #25
Raising targetSdk is not needed. Only compileSdk needs to be raised to be able to use support lib 28
nj...@gmail.com <nj...@gmail.com> #26
Right, sorry about that. Realized this soon after but couldn’t edit the response :(
oe...@googlemail.com <oe...@googlemail.com> #27
This issue is not fixed in 2.0.0-rc01. How can you consider calling this version release candidate with this bug!
io...@gmail.com <io...@gmail.com> #28
Supportlib 28 and AndroidX 2.0.0-rc01 releases are not related to navigation - navigation/workmanager are still in alpha in a separate release process. They have yet to release an androidx-package version, so they aren't included included in the initial 2.0 arch components release process. See https://developer.android.com/topic/libraries/architecture/adding-components#navigation - you need to update your navigation library version specifically.
be...@googlemail.com <be...@googlemail.com> #29
I faced the same issue after calling startActivityForResult and rotate screen and then return the resulting intent. I noticed that this also caused the onCleared() of the ViewModel to be invoked in the calling activity's viewmodel.
ti...@ageas.com <ti...@ageas.com> #30
Re #29, if you're still having an issue with 28.0.0-alpha3 or higher (or 1.0.0-alpha2 in AndroidX), please file a new issue with a sample project that reproduces your issue.
mi...@gmail.com <mi...@gmail.com> #31
Can anyone please make a sample project to test it out, and say what are the steps?
I think the issue was fixed, at least for loaders.
I think the issue was fixed, at least for loaders.
al...@gmail.com <al...@gmail.com> #32
"Retained fragments to hold the ViewModel" is not a reliable solution. After reverted some requested runtime permissions, such as Storage, Location and so on, retained ViewModel will be changed to a fresh one!
it...@libratus.edu.pl <it...@libratus.edu.pl> #33
I'm getting a similar issue. Multiple instances on my view model are being created on screen rotate. Here's a link to my repo: https://github.com/rahulchowdhury/elly/tree/add-elephant-profile
b....@snapaddy.com <b....@snapaddy.com> #34
Re #33 - you're unconditionally adding a new Fragment in your MainActivity, meaning you're adding a new instance for every rotation. You need to surround that code with if (savedInstanceState == null).
[Deleted User] <[Deleted User]> #35
Whoops. Totally missed that one out. Sorry. 😅
da...@gmail.com <da...@gmail.com> #36
@34 @35 Or check if the fragment exists, using findfragmentbytag .
bu...@gmail.com <bu...@gmail.com> #37
+1
[Deleted User] <[Deleted User]> #38
+1
[Deleted User] <[Deleted User]> #39
+1
al...@gmail.com <al...@gmail.com> #40
+1
he...@max-krause.com <he...@max-krause.com> #41
+1! Urgently needed.
vi...@lemontree.fi <vi...@lemontree.fi> #42
+1 We really need this one too.
ka...@cawstudios.com <ka...@cawstudios.com> #43
+1
jm...@google.com <jm...@google.com> #44
Orientation information should now be returned in 'boundingBox' object for Page Blocks [1], Paragraphs [2], Words [3], and Symbols [4] for all versions of the Vision API (v1, v1p3beta1, and v1p4beta1) [5].
[1]https://cloud.google.com/vision/docs/reference/rest/v1p4beta1/AnnotateImageResponse#block
[2]https://cloud.google.com/vision/docs/reference/rest/v1p4beta1/AnnotateImageResponse#paragraph
[3]https://cloud.google.com/vision/docs/reference/rest/v1p4beta1/AnnotateImageResponse#word
[4]https://cloud.google.com/vision/docs/reference/rest/v1p4beta1/AnnotateImageResponse#symbol
[5]https://cloud.google.com/vision/docs/reference/rest/
[1]
[2]
[3]
[4]
[5]
nj...@gmail.com <nj...@gmail.com> #45
Thanks for the update on this one, great to see it has been fixed.
However, could not see what additional information is provided to infer the orientation of an image in the updated boundingBox response?
What are the names of the elements in the response that provide this, and maybe an example of how to determine how an image should be operated on to make it upright?
Cheers!
However, could not see what additional information is provided to infer the orientation of an image in the updated boundingBox response?
What are the names of the elements in the response that provide this, and maybe an example of how to determine how an image should be operated on to make it upright?
Cheers!
jm...@google.com <jm...@google.com> #46
When orientation is detected, it is represented by the boundingBox vertex positions returned by the object types listed in comment#44 . Here is the documented description for the 'Page Block' type orientation:
"The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example:
when the text is horizontal it might look like:
0 ------- 1
| |
3 ------- 2
when it's rotated 180 degrees around the top-left corner it becomes:
2 ------- 3
| |
1 ------- 0
and the vertex order will still be (0, 1, 2, 3)."
"The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example:
when the text is horizontal it might look like:
0 ------- 1
| |
3 ------- 2
when it's rotated 180 degrees around the top-left corner it becomes:
2 ------- 3
| |
1 ------- 0
and the vertex order will still be (0, 1, 2, 3)."
ia...@dnlab.de <ia...@dnlab.de> #47
Can someone please add an example of where to find and how to extract this image-rotation?
jo...@nicefilmclub.com <jo...@nicefilmclub.com> #48
Well there be any support for this for OBJECT_DETECTION? I scan a lot of film negatives, and it would be amazing to guess the correct orientation of the image with a confidence score.
uz...@gmail.com <uz...@gmail.com> #49
Hello,
I don't understand
description: "0,13"
bounding_poly {
vertices {
x: 214
y: 147
}
vertices {
x: 215
y: 131
}
vertices {
x: 223
y: 132
}
vertices {
x: 222
y: 148
}
}
How should I interpret this to get the page orientation of my image (which is mostly text) ?
pr...@gmail.com <pr...@gmail.com> #50
+1
su...@insight.ly <su...@insight.ly> #51
+1
va...@veryfi.com <va...@veryfi.com> #52
jo...@nicefilmclub.com <jo...@nicefilmclub.com> #53
+1
pr...@gmail.com <pr...@gmail.com> #54
+1
ma...@gmail.com <ma...@gmail.com> #55
+1
je...@wizy.io <je...@wizy.io> #56
+1
sh...@gmail.com <sh...@gmail.com> #57
+1. Couldn't this be added in the last four and a half years this issue has been open?
ma...@whiterabbitjapan.com <ma...@whiterabbitjapan.com> #58
+1
al...@gmail.com <al...@gmail.com> #59
+1
tu...@gmail.com <tu...@gmail.com> #60
+1
jm...@google.com <jm...@google.com>
bo...@fetchpackage.com <bo...@fetchpackage.com> #61
+1
ju...@gmail.com <ju...@gmail.com> #62
+1
va...@veryfi.com <va...@veryfi.com> #63
+1
ja...@gmail.com <ja...@gmail.com> #64
+1
al...@gmail.com <al...@gmail.com> #65
+1
wn...@gmail.com <wn...@gmail.com> #66
+1
mc...@gmail.com <mc...@gmail.com> #67
+1
ke...@gmail.com <ke...@gmail.com> #68
Has this issue been solved yet?
My OCR results also seem to be output of images that are randomly rotated 0, 90, 180 or 270 degrees of original images.
My OCR results also seem to be output of images that are randomly rotated 0, 90, 180 or 270 degrees of original images.
ja...@mrcooper.com <ja...@mrcooper.com> #69
I see this is still in assigned status even after 4 years. Please expedite as it is already working in OCR, and needs to be exposed to the customers via response.
au...@gmail.com <au...@gmail.com> #70
I think I might have sorted it out, even if it is not perfect of course.
horizontal_text = []
for page in response.full_text_annotation.pages:
for block in page.blocks:
for paragraph in block.paragraphs:
prev_word = None
current_line = []
for word in paragraph.words:
word_text = ''.join([symbol.text for symbol in word.symbols])
y_diff = word.bounding_box.vertices[3].y - word.bounding_box.vertices[0].y
x_diff = word.bounding_box.vertices[3].x - word.bounding_box.vertices[0].x
if x_diff == 0:
angle = 90
else:
angle = abs(math.degrees(math.atan(y_diff / x_diff)))
if 45 <= angle < 135:
if prev_word and word.bounding_box.vertices[0].y - prev_word.bounding_box.vertices[3].y > \
threshold:
horizontal_text.append(''.join(current_line).strip())
current_line = []
current_line.append(' ' + word_text)
prev_word = word
if current_line:
horizontal_text.append(''.join(current_line).strip())
return '\n'.join(horizontal_text)
ar...@gmail.com <ar...@gmail.com> #71
Google is evil.
co...@eversionsystems.com <co...@eversionsystems.com> #72
+1 I created a bug about this today but have just realized this is talking about the same issue I am having, 6 years on and it's still not fixed!!
gi...@evolution.ai <gi...@evolution.ai> #73
+1
[Deleted User] <[Deleted User]> #74
+1
ya...@gmail.com <ya...@gmail.com> #75
+1
bi...@gmail.com <bi...@gmail.com> #76
+1
Description
I found that Vision API still can recognize the characters.
(Please see the attached screen shot)
However the response doesn't include the correct orientation of recognized text.
If I get the correct image orientation, I can help user to rotate/display the image correctly.
I would expect this request is not complicated, since the algorithm already make it.
p.s.
The api version I am testing:
com.google.apis:google-api-services-vision:v1-rev30-1.22.0