Data synchronization from an android content provider to my remote server - android

I'm developing an app (Android 4.0) which relies on a background service to sync specific data from probably sqlite to a remote mysql database.
I am pretty new to Android dev (but not programming) and hence am still struggling with where to begin and how to construct the system. I am planning on leveraging:
"Developing Android REST client applications" by Virgil Dobjanschi (2010)
as a starting point. What he demonstrates is a high level approach to developing such a system which is excellent.
My question is, in two years or so has anything changed, or would this still be considered a viable approach? Any other help you can give having gleened my situation will help me immensely.
Thanks.

Here is an updated approach that I have found very useful
Use an Intent Service to get off the main thread for your requests. If you want more info about services refer to this.
Hope this helps!

Related

How can I update app content frequently?

I'm new to app development and I am soon going to be developing an app for a local charity.
The charity is a dog rescue charity and the app will display information about dogs available for adoption.
The content will obviously need to be updated frequently, even daily, which will obviously not work constantly updating the app via the relevant app stores. What is the most common way to deliver content to an app?
My thoughts on previous experience would be to create a REST API and deliver the content remotely. Would an app allow this? Is there a method more generally used?
Thanks in advance.
You can save all the information to show of each dog available to adoption in a database, then make the app retrieve all the data from it every n time.
I recommend you to use Firebase, it is cross-platform (includes Android and iOS), and I consider it really good when starting using databases.
Here you can find documentation for every supported platform, and easy examples on how to work with it.
Good luck with your project! :)
I see you don't have clear specification on how often to update the app content and technical capability.
Use JobScheduler
Syncing to the backend (via REST API)to fetch the data is a battery drainer & there is no use in syncing data on device which is about to die, I would prefer Jobscheduler which will intelligently act as per various environment criteria met like charging/idle.
There are several facilities available to help your app schedule work. These include:
AlarmManager
JobScheduler
SyncAdapter
Caution: Exponential backoff is enabled on job dispactchers/schedulers
For 24-hour logic check here

ASP.NET MVC background work - Best practice

I'm developing an ASP.NET MVC 5 application which is supposed to receive and send messages to Android smartphones. The way I have currently implemented it is by using a message broker (RabbitMQ in this case) and let that broker handle the communications between the backend and the smartphones.
In the ASP.NET code I am creating a thread which is run at the beginning of the application in global.asax (I have seen some people who recommends this, maybe I am doing it wrong...). This thread is in charge of listening to the messages that the broker receives and then process them.
My question is: is this a good practice in terms of handling external messages in an ASP.NET application? This is the first time I program this kind of applications and I don't know if I am doing the things right. Does anybody know another ways to receive messages from an external device in ASP.NET? Again, keep in mind I'm very new to ASP.NET, maybe I am asking something stupid but I just need some information about this.
Thanks!
In case someone has a similar question I will answer how I made it work. At the end I used HangFire (http://hangfire.io/), it is quite easy to configure, just need to add this code below in Startup.Auth file:
GlobalConfiguration.Configuration.UseSqlServerStorage("db_name");
app.UseHangfireServer();
app.UseHangfireDashboard();
And the following code to start the background task:
var storage = new SqlServerStorage("db_name");
var client = new BackgroundJobClient(storage);
client.Enqueue(() => rabbitInstance.MethodXYZ());
I hope this solution is helpful for more people.

Saving/Serializing OkHttp/Retrofit Requests

I want to be able to recover from crash/closing the app or just device being disconnected.
Currently when I detect that the network is out for my Android device I save the Call created with RetroFit2 in a stack (to process later). If the user were to close the app or restart the device I lose the possibility to save these calls anywhere...
My question is the following, how can I save a RetroFit Call or an OkHttp3 Request?
None of them is serializable or nor can I convert them to strings from what I could see looking at the code.
Use android priority jobqueue by Yigit Boyar (one of the google android guys). It'll serailize your jobs, detect network changes (and respond accordingly) and persist even through device reboots (let alone app crashes). Plus a ton of other features. Just take a look. It is not exactly what you requested but it's a better solution. It's Magic.
Starting with v2, Job Queue can be integrated with JobScheduler or GCMNetworkManager. This integration allows Job Queue to wake up the aplication based on the criterias of the Jobs it has. You can see the deatails on the related wiki page. The Scheduler API is flexible such that you can implement a custom version of it if your target market does not have Google Play Services.
Try it and you'll be glad you did, as I've been. It filled the huge gap in my code that I spent weeks hacking together with spit, ducktape and faith.

Syncing offine data with server?

This may be duplicate question but am still having doubt am a beginner in android application i have a couple of doubts my primary doubt is:
I have made one application which will communicate with server when network available it will work as it is. when network is not available data will save in sqlite and later when network is avail need to sync that data to server how can i achieve this.
Whenever there is new update is made with server need to get notification how can i do this
For this one which will be the best approach syncadapter or server or intent service with broadcast receiver which would be opptimized solution for the above requirement
These are all my doubts i would be very glad if someone helps me !!!
If you want an Android app to be notified when something happens on a server you control (without having the app to constantly poll the server to ask for changes), the usual solution is to use Google Cloud Messaging to allow the server to send a notification to the app to tell it to refresh data.
It is kind of complicated to implement, but is the best way to do what you want and is standard practice for mobile apps.
If you need to know when the network becomes available, to reach your server for synchronization, implement connectivity change listener, as discussed in this question.
This does not allow to send messages from the server easily, but if the server messages are not of high urgency, maybe you can simply check for them periodically.
This would allow to use less Google specific infrastructure and change the cloud providers easier.

Android - Basic CRUD (REST/RPC client) to remote server

There are lot of discussion about REST client implementation in android, based on the talk at GoogleIO 2010, by Virgil Dobjanschi. My requirement may not necessarily involved, as I have some freedom to choose the configuration.
I only target tablets
configuration changes can be prevented if no other easy way (fix at Landscape mode etc)
I am trying to achieve.
Basic CRUD operation to my server (JSON RPC/ REST). Basically mimic an ajax request from android app (no webview, need native app)
Based on the above mentioned talk, and some reading I see these options.
Implement any of the 3 mentioned in the Google IO talk
Especially, the last pattern may be more suitable as I don't care much of caching. But not sure how "real time" is sync implementation.
Use HTTP request in AsyncTask. Simplest, but need to avoid re-sending request during change in device configuration (orientation change etc). Even if I fix at one orientation, recreation of activity still happens. So need to handle it elegantly.
Use service to handle http request. So far, it say use service for long ruiing request. Not sure whether it is a good approach for simple GET/POST/PUt requests.
Please share your experience on what could be the best way.
EDIT:
Further search reveal some nice posts and code samples.
Spring for Android
RoboSpice
Using Loader
Using service
I am thinking about doing it through service. Please comment your suggestions.

Categories

Resources