I am new in android and developing an android application in which admin can insert data on server and users can load that data on their devices. I don't want to load data from server every time user land on that activity. I want to save fetched data at client side using greendao and load only the new one. And i think i have to hit the backend at least once. I am looking for a most convenient method to achieve this.
My preferred way would be to track the device on the server side:
for example create a table like cachedDevices(deviceId,dataId). then whenever you are requesting new data, your server could query your data against cachedDevices internally and only send new data...
you should also be aware of that each device should have unique Id...
Related
I have used the following code:
CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);
It is working fine. But, when the user restarts the application, the cookie gets deleted, and I can't use it for further rest calls.
How can I store the cookie permanently in the Android app?
There are multiple ways using which you can save data permanently (until you can'y clear app data).
SharedPreference
Local Database (SQLite / Room - Recommending)
Using above listed methods you can store you data and also get those data after restart of application/mobile phone.
You can get an idea of access of above listed methods using below links.
SharedPreference : https://www.tutorialspoint.com/android/android_shared_preferences.htm
SQLite : https://www.geeksforgeeks.org/how-to-create-and-add-data-to-sqlite-database-in-android/
Room : https://www.geeksforgeeks.org/how-to-perform-crud-operations-in-room-database-in-android/
Thank you.
I am developing a menu app for restaurant , I want the user to be able to add a new dish (new row in a table) and when the row is added to the database all other users (who have the app in their device)can see the new update.
I want to use SQLite. is that possible if yes, how?
For such kind of scenario, you need to store the new menu item from a user on backend database (a database which is hosted on an external server) of your application, and all the other users using the application will get that data by calling a web call to your backend.
Requirement is to sync mails from Gmail for an user into our CRM. The system in place is based on Google Pub/Sub which watches inbox of the user for any change and fires the notification to our HTTPs endpoint. More on this at Gmail cloud pub/sub.
Based on the above procedure we git history of changes. And then i am interested in only new messages, so history.getMessagesAdded is preferred as per this guide. Issue we are facing now is the first mail of a thread is not captured under messagesAdded all the subsequent messages are passing through our system.
Note: For the first mail, we do get push from Google. But when we try to get Messages added it turns out empty. Is there anything special needs to be done for the first mail of the thread or am i missing out something.
I was experiencing a very similar problem, and my mistake was that I was using the historyId from the push notification, the solution was to store the last known historyId on my database, so, every time I get a notification, I get the history from the id I have stored, not the one from the notification.
In my case, the historyId from the notification doesn't even make part of the history, maybe because of my watch restrictions: labelIds=['INBOX']
This is the google pub/sub notification:
{
message:
{
data: {"emailAddress": "user#example.com", "historyId": "9876543210"},
message_id: "1234567890",
}
subscription: "projects/myproject/subscriptions/mysubscription"
}
I was using the message.data.historyId, wich was causing the confusion!
The message.data, comes as a base64 encoded string, in this example I just decoded it!
Step by step for watching new e-mails on the inbox:
Do all the configuration in the google pub/sub.
Start watching the user with the filters you want (docs.: https://developers.google.com/gmail/api/v1/reference/users/watch)
Store the historyId obtained in the step 2
When receive the notification, get all the events (history) using the stored id as the startHistoryId parameter (docs: https://developers.google.com/gmail/api/v1/reference/users/history/list)
In the history list obtained on the step 4, look for the new messages: history.getMessagesAdded().
Update the last known history id in your database, so you don't need to deal with the whole history every time!
I hope it helps.
my boss asked me to develop an webservice that should work in this matter:
an external app contact my app and:
if the method used is GET and the url contacted is:
http://localhost:8080/webapp/webservice/?findall
will return all rows find in a table;
If the same external app contact my app in the same method but send a key and a value like:
http://localhost:8080/webapp/webservice/?field1=value1
my app will return a set of rows filtered by field/value.
And soon on with with any method sending request and with other fields.
I know how do the operations using JPA 2.1 but how mapping the actions?
Someone could help me to starting in the right direction with JDK1.8?
I am working on app running on two tablets, which have two type of logins. Customer and Shopkeeper, it will run on two tabs at same time. I am getting tabs device id and saving it. because it can't be run on any other tablet without registered tablets.The issue is that after login when I go on main screen, when i enter number from any tablets, the next screen must be changed on both tablets. I am not getting the idea how to operate two tabs from any one of them.Can you help me to get this idea. any help will be appreciated.
I have 2 separate options here :
A. Use CouchDB.
Couch DB has this functionality to sync data between client and server.
Steps :
Tablet1 enter a value
Value saved in tablet1 CouchDB. (You can use something like couchbase-android)
Data synced from client COUCHDB to Server CouchDB ( you can use Cloudant here )
Data synced from Server CouchDB to client CouchDB in the Tablet1
Tablet2 use a listener to listen to record change in the database
Tablet2 change its state based on the record change.
B. Use Notification Server
Tablet1 enter a value
Tablet1 send message to Notification Server, indicating the changes
Notification Server send notification to Tablet2
Tablet2 use Notification Listener to listen to all notification
Tablet2 change it state based on data contained in the notification message.