-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling app sleep / screen lock / Activity pause #74
Comments
Thanks for your question and thanks for doing the research in the old issues first! There are two similar issues that are certainly hard to find because they use other terms: We definitely need to know more about your Have you thought about using this library from a background |
Thank you for the reply. I have a basic app which consists of a LoginActivity (separate Activity), an OverviewActivity and multiple fragments (e.g. ListInvoicesFragment). The Meteor connection is created in the LoginActivity and is persisted in the application context for global accessibility. I understand that a paused Activity, by definition, can not receive the changed data over the network. To sum it up, do you think that when an application needs to be used with interruptions (screen locks, app switches..) using a Thank you again, much appreciate the help and this lib! |
I think so, too. And that question hasn't really been answered yet, neither in those related issues.
Does this mean that the reference to the Meteor instance is kept in a subclass of First, you should check why the subscription data is outdated when the A background Regarding the But I'm not sure if the So let's first check why the data becomes outdated at all (see above) and whether we can fix the normal access patterns. And thanks for your appreciation! |
Indeed, it is. I have a custom class for the application's context extending What struck me as odd is that when I change more of the data (e.g. add a new record or modify the record once more), the data automatically syncs again. That is, even when an unrelated event occurs (changing data instead of adding, for example).
after this, the data of the two added invoices shows up on the client as well. It's almost as if the callbacks are delayed when the app is paused. I do not currently remove the callbacks anywhere. I will be removing them by user interaction only (logging out or explicitly exiting the app) in the future. |
That all sounds good! No reason to assume a bug in your application design.
That sounds good as well. Since you can't detect when the whole app is killed by Android, anyway, this is probably the best solution. Thanks for your debugging work so far. The fact that all data sets are sync'ed again as soon as you perform any (unrelated) action is very good news. And, of course, some little bad news since we don't know yet why this is happening. But that should be much easier to debug and resolve. What you could do is:
Please log everything and inspect the places before and after the screen goes off (and on again) and when your perform the (unrelated) action that makes the sync work again. |
Okay, some more input from the test bench here. One more observation I made, just since it seems curious: the app does notice a dropped connection, even when the screen is locked. Both onException and onDisconnect are called as you would expect and custom UI updates (displaying a material design Calling a non-defined method on the server does not sync the data sadly. |
Thank you!
Now do you get If these callbacks were called, that would be good news again :) The exception could even have a reason and details included. And then, why does the connection come back again? Is this the built-in reconnect attempt? Or is it due to some other reason? Do you get We have to find out why the connection comes back again and what triggers the sync to work again. As you wrote in one of the last comments, sync seems to start working again when you write some (unrelated) data. Some other activity, such as calling a method, does not work, as you noted. |
I do not get |
Thanks, that was not irrelevant at all. Got it now :) Actually, it's quite important, isn't it? The explanation for the difference between One could verify this by calling some method after locking the screen (e.g. scheduling a task 5 seconds after Sorry for this problem which requires quite some amount of debugging, apparently. |
I have just done the proposed quick test. I've defined a Meteor method on the server which just echoes something to the console. Then I have set up a delayed |
Thank you for testing this! Could you please add That should help with debugging. Usually, you should even be able to see If we tried to sum up what we have found out so far, this would be that everything works fine when the screen goes off, except that data updates are not sent anymore until the client modifies some data itself again. Right? |
It will take me a few more days to get back on this to you. Sorry for the delay and thank you for the support thus far. |
No problem. Thanks a lot for helping debug this problem! Just get back to this issue when you have some new information :) |
After some more debugging I once more lean towards the side of a bug in my application design. I will have to do some more testing in order to confirm this. It could be that the issue I reported here is indeed more of a question than it is a bug.
but nothing out of the ordinary and nothing that would let me suspect a flaw in this library, am I right? thank you once again for the work you put in here! |
Thanks, @rjhllr! That does indeed look good and the pings and pongs seem to go through. So one might think it's a bug in your application code. But a few weeks ago, you came up with the following findings, didn't you?
|
Good day to all of you,
after searching the repo for certain keywords (sleep, onResume, lock..) I didn't come up with an issue talking about this topic and it's not clear from the doc either.
I've written an app that consumes and manipulates data on a Meteor server. Now this app is expected to be used on-and-off over a period of some hours. This, of course, includes users locking their screen and/or switching to a different app from time to time.
I've done a test where I add a new document to a collection and update an existing one after having locked the screen. When I unlock the screen again, I come back to my activity which remains unchanged. When I then add another document or update one, all documents update accordingly.
From this I deduce that the app does not know about changes that happen when the Activity is paused, which is what I'd expect.
Taking a guess I'd say that I have to implement some sort of "refreshing" in the onResume method of the activity. I have already tried calling disconnect/reconnect there, which does not work (probably because of the login which is needed for each and every method).
I'm sure there must be a better solution though.
Thank you!
The text was updated successfully, but these errors were encountered: