I want to implement chat between two users in mobile, I'm using android studio and store the messages in AWS(amazon) MySQL database.
I manage to read messages every time user starts the chat activity like so:
void onCreate() {
readHistoryMessagesFromLocalDataBase();
readMessagesFromGlobalDataBase();
}
The first function is used to read the history messages from the local database of Android using SQLite.
The second function is used to read any new messages waiting on the global database of Amazon using MySQL.
This works perfectly, but how can I receive messages in real time while I'm already in the activity without reloading or refreshing?
Is there any data change listener to achieve this goal?
Related
I have spring boot application with basic REST API.
My question is what shall we use to download some bulk data? What is preferable way how to download bulk data without memory leak? Let's suppose we have 10 million records.
Here are some approaches but not sure:
download with PipedInputStream when data are written with PipedOutputStream in separated thread. Is it fine or it is not good choice?
download with ByteArrayOutputStream when data are written into temp file in separated thread and after finish it is ready to download. We can mark this operation with some flags for end user eg. DOWNLOAD_ACTIVE, DOWNLOAD_DONE. The user is just initiating download with result flag DOWNLOAD_ACTIVE and trying to ping server for response flag DOWNLOAD_DONE. When it is done then the user is going to send request to download data.
Summary 2)
1. initiate request to download data - ACTIVE state
2. ping server and server returns current state - ACTIVE or DONE
3. if final state is DONE then user initiate final request to download data
Thanks
You can use the second approach. Which can prepare data in the background and once it's ready you can download it.
Send a request to prepare data. The server responds with a UUID.
Server starts preparing files in the background. The server has a Map that has the key with a new UUID and value as status ACTIVE.
Client saved UUID and checks the server after a certain interval by passing the UUID.
Once the server finishes the task it will update the Map for the given UUID value as status DONE.
As the status is DONE next request will provide the status DONE and UI and send another request to download the file.
The above approach will only work if you don't refresh the page. As page refresh will clear the UUID and you have to proceed again.
To achieve this after refresh/cross-logins then you need to use a database table instead of Map. Store the username along with other information and inform the user once it's ready.
I have Oracle database (version 19c) with table CHANGE_LOG. I have also a Java & spring application, lets call it CLIENT_APP. I need to perform some tasks from CLIENT_APP when something is inserted to CHANGE_LOG table: send message using RabbitMQ to external application APP_EXT, log that message was sent, call some another APP_EXT_2 to recalculate something based on id from CHANGE_LOG table.
Is there a way to listen for changes in Oracle DB (other than sending query in some time interval to search for new records)?
Or maybe the only solution is to create Oracle trigger sending some notification to my CLIENT_APP to perform all required things?
What is the best solution to perform such operations?
I am really rookie and need an advice.
I have read documentation, and as far as i understood if you need send direct message, follow next steps:
Make authentification, eventually you get Firebase TokenId and
userId
Send them to your server side and store it in DB
When you are going to send a message you need create json and put
inside topic text and resipent userId so on...
Send this json via HTTP to your server side
When server retrive this json, it should use Firebase API to
create new message bloc child with random name in firebase
Eventually server have to find recipent user in DB by userId that we get from message.
After server will find current recipent user by userId , next we should take firebase tokenId In order to sent notification .
And send recipent user notification with such data - name of new
message bloc child
Recipent will connect to this current bloc and retrive data
It is as i understood this consept, fix me please if smth wrong?
Your suggested approach sounds good. The most important thing to realize is that you require an app server to send a downstream message to a device. Using the database as the communication mechanism between the app and the app server is a popular approach.
You could also use Cloud Messaging's upstream capabilities. But I've never tried that approach, because the database works fine for me and I had little interest in learning yet another protocol (XMPP).
You can read how I implemented it in this Firebase blog post Sending notifications between Android devices with Firebase Database and Cloud Messaging.
Now, I save data in datastore of google cloud.
module-backend
#Entity
public class ComprarProducto {
#Id
private String producto;
private boolean comprado;
public ComprarProducto() {
}
public ComprarProducto(String producto) {
this.producto = producto;
this.comprado = false;
}
...
}
Example data of CompraProducto
This data is displayed in a listview. When I add one item, the list is updated and saved in datastore.For save data I use AsyncTask in app.
Then, If I add one item in device1, I want to see that listview as both device1 as device2 is updated, but I don't know how to do it.
I use too GCM (google cloud messaging) and I've got to send a message to devices but only this. I want to see the data update in the device 2 without taking any action.
I want to see the data update in the device 2 without taking any
action.
This is not possible without somehow notifying from the backend server that new data has been saved to datastore. Sending a push notification to device2 (or all other devices or whatever) would definitely be the correct way to do it. What you do is have the push notification tell device2 to query datastore.
If you really don't want to use GCM you COULD have device2 just query datastore every couple minutes but that is not recommended. The correct way to do it is to use GCM to give your device2 a "tickle" to indicate that there is new data in datastore and to query accordingly.
Not sure what kind of app you are building but these are some options.
i have an android app that gets data from mysql database, now i want to implement refreshing capabilities such that when new entry is entered int the database then everyone having the app will be able to see the new entry after sometimes even without restarting the app again. how can i do that.?
i have tried to use
Intent i = getIntent();
finish();
startActivity(i);
but it does not do what i want as it refresh the activity but does not load new entries.
You have to implement the code to fetch the new data from the db and update the entries in your onResume() method of this activity for your code to work.
If by entries, you are using a ListView, you could also use adapter.notifyDataSetChanged() to refresh the data without having to finish and restart the entire activity. (Taken from this post)
In your Activity you will be calling a API to get data from mysql Database. Now you need to call that API after a fixed interval of time to get data from mysql database again.
If new entry is added into the database you need to send push notification to all users about the updation. You can also implement automatic refresh when such notification is received by the users.