Skip to content
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

How to observe Datastore Model Realtime on background or after killing application #1488

Open
iamAliRaza opened this issue Sep 7, 2021 · 5 comments
Labels
datastore DataStore category/plugins feature-request Request a new feature

Comments

@iamAliRaza
Copy link

Hey guyz!! I want to observe my model if the application is in background or if user killed the application from recent apps.
In that case please let me know the best approach for listening to datastore events.

I Tried some ways but due to background restrictions in android none of the method is working correctly..

Any solution??

Amplify.Datastore.observe(Messages::java.class, {},{},{},{})

@raphkim
Copy link
Contributor

raphkim commented Sep 9, 2021

What type of datastore events are you hoping to listen to?

If you wish to subscribe to operations involving a specific type of model (e.g. new Messages was created, or an instance of Messages was edited, etc.), then you are using the correct API. However, you do not seem to be providing any callback for the events, which basically means that your code is completely ignoring any changes being made to Messages. Please refer to our documentation for observing on DataStore models with callbacks here.

If what you wish to do is to subscribe to generic DataStore events (e.g. DataStore is now finished syncing remote models locally), then you can use our Hub category to subscribe to those events and act on them.

@raphkim raphkim added closing soon This issue will be closed in 7 days unless further comments are made. datastore DataStore category/plugins question General question labels Sep 9, 2021
@raphkim raphkim self-assigned this Sep 9, 2021
@iamAliRaza
Copy link
Author

iamAliRaza commented Sep 10, 2021

@raphkim Yeah actually i am talking about to observe specific type of model like i mentioned - Messages::java.class -
and above this code Amplify.Datastore.observe(Messages::java.class, {},{},{},{}) i intentionally left it blank. Just for showing that my question is related to Observe Specfic Model. Its working fine if i am observing it in MainActivity or anywhere when i am using the application. My problem is i implemented chat. So if the user is not using the application and he killed the application from recent apps after using it. Then how we can observe model. i want to get new messages in background like Whatsapp etc... Is there any best approach how can i observe model mutations in background. Because of background restrictions in android nothing is correctly working : Services, Background tasks etc...

@raphkim raphkim removed the closing soon This issue will be closed in 7 days unless further comments are made. label Sep 10, 2021
@raphkim
Copy link
Contributor

raphkim commented Sep 10, 2021

It looks like I misunderstood the original question! I apologize for that.

Amplify Android currently does not support realtime observation while the app is in the background. We will track it as a feature request and prioritize it based on how much traction it receives.

@raphkim raphkim added feature-request Request a new feature and removed question General question labels Sep 10, 2021
@raphkim raphkim removed their assignment Sep 10, 2021
@iamAliRaza
Copy link
Author

@raphkim ok thanks

@poojamat
Copy link
Contributor

Push notification to achieve your use case will be better strategy.

@poojamat poojamat added the pending-community-response Issue is pending response from the issue requestor label Feb 11, 2022
@lawmicha lawmicha removed datastore DataStore category/plugins pending-community-response Issue is pending response from the issue requestor labels Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datastore DataStore category/plugins feature-request Request a new feature
Projects
None yet
Development

No branches or pull requests

4 participants