Android | RESTful + (SyncAdapter or AsynTask) - java

I am building an application that will communicate with a server through a RESTful api and I'm not sure which one to use (SyncAdapter/Asyntask).
Basically, I have to update my SQLite database everytime the user logs in (in fact, I believe I could do without the SQLite dabase as the data in the Sever DB is very volatile and changes quickly). (the app would be holding on to old data)
Right now, I'm just saving data on local variables (arraylists) I don't mind then getting lost when the user leaves the app. Also, I'm making http requests using an Asyntask. Is this a good approach? I'm not really sure.
Is SyncAdapter a good fit for my use case? Should I use a SQLlite DB? despite the fact that I don't want to persist data in my app.
Thank you

Related

What database should I use in order to store highscores and users information from my app I want to publish on GooglePlay Store?

I am making a cross-platform mobile game with Js, HTML, CSS, and Cordova.
First I want to compile it for Android and place it on GooglePlay Market. The thing is that I can not find information on the ways to store data from my game, like high scores, users etc.
I mean I couldn't find any information about Google's requirements on this matter, before you submit the game package to them for validation.
It is not clear, shall I use Firebase or I can use any DB server or a shall make a local file somewhere.
You can use Google Firebase if you are planning any kind of notification service on your application. if you are expecting heavy customer transactions then go for AWS.depending on your use case ,You can either choose AWS Relational data base service or NoSql service.
AWS RDS : https://aws.amazon.com/rds/
AWS NoSql : https://aws.amazon.com/dynamodb/
Data would be more secure, scalable and high availablity.

Are multiple Firebase Database Child/Value Listeners efficient for mobile app?

I've been reading about Firebase Realtime Database for a while now I'm just wondering about the whole idea of event-driven data fetching from database. If data is downloaded from the database only when there was a change made to it, then it should be much less demanding on the device resources like battery or Internet connection. I thought I could remap the whole database fragment I need in my Android activity with my model objects that reflect the structure of my database and update its values with Child/Value listeners. Then I would have the whole data I need in a flexible form of POJOs and it would update every time there was a change in the database. So it is actually a real-time solution. But I wonder if such number of listeners would slow down or overload user's device in any terms like battery life or data transfer.
So, would It be a good solution to reflect database state in my Java model objects or should I go another way?
Could anyone resolve my doubts?
Thanks!
The listeners are triggered only when something is changed in the database. So you get data only when needed. It is expected that your app will lose their socket connections when there is no visible activity. That's the way the Firebase SDK works. Also, Android will aggressively pause background applications so they don't consume data and battery when the user isn't actively using it.
When you restart an activity for example, the Firebase SDK attempts to restore the websocket that it uses to communicate with the server. This websocket is fully managed by the SDK.
Hope it helps.
Firebase.addvalueeventlistener() only work when there is any change or update in database you are requesting. And it is a good way to move with JAVA objects or you can also use HashMaps<>.
As far as there is concern for device battery and performance then instead of requesting whole database you try to get only that part whose change event you wanna track.
And if you also want to have grabbing data on background as Whatsapp you can you Broadcast Receiver for internet and startservice() for where Firebase.addvalueeventListener() used.

Firing events on Android and Desktop Java when a database changes

I'm currently trying to work out what technology I can use to fire events remotely when a database changes, a realtime database of sorts. There is both an android application and a desktop JavaFx app that will communicate via the same database. When the data is changed from the desktop side, I'd like Android to update its data, and vice versa when changes occur on Android. Is there any method to achieve this without polling the DB for changes regularly?
I looked into Firebase and it seemed perfect, but lacked a desktop java library. Similarly, I have experimented with Amazon AWS Lambda and DynamoDB, and I can get a Lambda function to fire when the DynamoDB table changes. I can't however find a way for the Lambda function to update the Android/Desktop application that the data has changed though.
The JavaFx desktop application is a requirement of the project.
Apologies if this isn't possible, or if I'm overlooking a well known platform for this issue. Any help would be greatly appreciated.
No you not need the process of polling to achieve your results. To answer the first question, first the most flexible and plausible approach would to built a middle ware to intercept any changes.
Create a script to fire events whenever the data base changes. Wether by a time interval.
Second create server, a real-time server to fire such events to any client.
Third, the java fx client can use native observable for such a task. However i proposed going with a common listener, a perfect choice would be socket.io, there web-socket implementation available for android and vanilla java. For android client, whenever a data is inserted , transformed etc , use a broadcast receiver(local) to fire events in the to notify the server. Or use the socket.io connection to send events. Thats pretty much it.
Firebase + Cloud Functions for Firebase sound perfect for your use case. If the matter is pure Java support for Firebase, rather than Android, you might want to check out this question Get Firebase to work with java, not Android

how to send post data continuosly to web and mobile

I am going to develop uber-like application.Here I have to send latitude and longitude to web and mobile devices continuously with my service,What I have do to get this.
Can anyone please give some idea.
You should start by designing how the application is to be used, seen from all the different users perspectives.
For instance is this a web app, or a native app, or both?
Then from that knowledge, you need to define a communication protocol.
You should be able to determine if the client will be polling for data, or if you need to push it from the server onto the clients.
This also goes for the data that travels the other way.
From here you choose a language for programming, and then start doing some proof of concept tests.
The choice will depend on the chosen underlying technologies
(web / native / os / available libraries)
After some test work you may have something that works, then you need to review or add security to the communication, cause we do not want everyone collecting location data from everyone that has the app installed.
Then run beta trials and eliminate the worst bugs, and then release the app.
You'll want some sort of asynchronous task which can get new data from your server and refresh the mobile and web content to reflect the content of the server. You'll also want to notify the server whenever you make local changes to content and want to reflect those changes. Android provides the SyncAdapter pattern as a way to easily solve this pattern. You'll need to register user accounts, and then Android will perform lots of magic for you, and allow you to automatically sync. Here's a good tutorial: http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/

Connect multiple desktop apps to one online database

I'm starting a new project. It consists of:
Java desktop application downloadable from the internet with a client database.
PHP website on the internet with a server database.
The user who downloaded the app will use it to add items (not important what are they now) to the local database offline. When/If he is online, the item will be added to the server database so other connected users (through the desktop app or through the website) will see it.
I googled the issue and found it's more complected than I guess. One of the solution is to use some ready tools like SymmetricDS and Daffodil to gain in term of security, performance and scalability, but they're difficult to configure and install in both client and server side, and need the access to command prompt which requires me to pass to a dedicated host (well, that is not a real problem). Also, all what I want is just what I've described, not all what these tools actually provide.
Can I achieve that by myself within my Java application and maybe with the help of
the web server PHP?
I'm using MySQL for the info.
Edit: what really matters is to send items to the server database. Reading it can be less tricky using RSS Feed reading, for example.
Basically, you can use HTTP/HTTPS API. When a user online, send items to your php file and mark the items "sended" at local database. But you have to control edited or deleted statuses. So, yes that is much complicated but a solution.
Well the easiest solution that comes to my mind would be to save for each item a last edit date (on the server as well as on the client). Additionaly you have to keep track when a client got his last update from the server.
So whenever a client goes online the server sends him all updates.
But for that you have to make sure that the time on the client and the server are the same, and it doesn't solve the problem what happens if two clients edit the same item.
CouchDB solves the distributed synchronization problem very nicely, but it is a NoSQL DB. Depending on what your application should do, using it would boil down to using instances of CouchDB both locally inside very application, and on the central server.
You'd have to deal with conflicts nevertheless. The only thing CouchDB will support you with is easier detection of conflicts, and the data of both conflicting edits, so your application can work it out either automatically, or with user help.
On the other hand, generatin a unique id on the central server can be as easy as adding the creating user's id to each item id.

Categories

Resources