Replication between Android and Sql Server - android

I want to do the replication between sql server & android sqlite.I have done downloading(sql server to Android) using WCF service.Uploading part also that way I can do it.
My Problem is: After user change/enter table contents (e.g enter new invoice), it should start the upload(sqlite to sql sever) backed without effecting my current work/activity.
How we can implement this?
If it is mutithreading how it is possible.Need to run two activity same time.One will run foreground other one run in background....
Please help me or give me idea reading this?
Thanks in advance?

The recommended design practice for this is to use a content provider which handles concurrent thread access to the database.
To handle the background service actions, just implement an IntentService and simply call startService(intent);

Activity will be used for foreground tasks. Using that User can interact to your application. In Android we have a Mechanism to do long running task in background using Services. But it doesn't mean you should write your code to upload the data on server in Service only. Give service a task to just invoke a background thread and tell that , Upload data to server. Using AsyncTask you can achieve this.
So the flow should be. Activity --> Service --> AsyncTast --> To Your Server.

Related

How to update app content when app is suspended in background

I have an Android app that has a service that handle Firebase messages. So far it's working for me and I receive messages properly even when app is in background. What I need is somehow update app content when a message is received. That mean use network to contact backend and download fairly long JSON data and put them in database.
I have model in repository which I use in Activity. Now I am considering whenever I have to somehow call activity and refresh data but I think activity is somewhat dead when app is in background? So I don't know if it is even possible.
I can download data inside the service but my understanding of service is that it shall be lightweight and all the model and network calls seems to be a bit overkill for the service. Am I wrong?
What is ideal solution considering standard android architectural approach? Thank you.

Getting data from server regularly even when the app is closed

I want to get data from the server and store it in a cache regularly, even when the app is closed. I am not sure what is the correct way to do it. I have listed down the possible ways I can think of. Please let me know the correct or the best way to do it. Really appreciate any help.
Create an Activity and set a repeated alarm to call a service. The service should connect to the server and download the data in cache.
From a fragment, check the last time the cache was updated and then if the data is out-dated, connect to server in a background thread and update the cache.
You can Directly Use IntentService for Frequently Updating Data
IntentService is a subclass of android.app.Service class. A stated intent service allows to handle long running tasks without effecting the application UI thread. This is not bound to any activity so, it is not getting effected for any change in activity lifecycle. Once IntentService is started, it handles each Intent using a worker thread and stops itself when it runs out of work.
IntentService would be an best solution, If you have an work queue to process. For example, if your application using analytics you will likely to send event name and related parameter to your tracking server for each user generated event. Although each event means a tiny piece of data, creating networking request on each click will result an overhead to your application
For implementation : Updating Data from Server Using Intent Serive
Do take a look at Android Sync Adapter Framework.
https://developer.android.com/training/sync-adapters/index.html
Hope this helps.

Is it appropriate to use Service for making update of user`s profile

I'm trying to develop a user profile with it's favorites, datas, etc. It it good to synchronize device's profile and remote profile of user with Service? Or usually it is enough to make request in separate thread?
If you want to use service make sure you use IntentService
If you use normal service it will run on Main thread which is not good approach in case of
asynchronous operations.
You will basically need IntentService and ResultReceiver.
You can check following to learn how to implement them
how to create own download manager in android 2.2
Hope this help.

Android Thread & ASynTask

I want to implement the thread in my application
first requirement is:
Each activity access the local database that time it take some time to load.So I am planning to give progress-dialog.I want to do it in thread.Currently I did using the AsynsTask because of I dodnt know how long will take for record. Other than AsynsTask How we can implement using Thread?
Multitasking Facility :
I want to run two activity.One is in background.I.E If there are any upload available(Database Syn Android to SQL Server) while running activity ,Upload should start in background.How we can implement this?
Please guide me on this
Thanks in advance
You want to synchronize your database in background so I think you have to use service in which you have to implement thread and you have to write your code in thread.
You can then schedule your service startup time and also you can repeat your service when ever you want to keep duration for start service.
And for upload you have to options
1) Using AysncTask
2) Using Service with thread
And also know that Service is running in main UI so if you want to use service for synchronize database you have to implement thread
you can execute many AsyncTasks in the background, but only one Activity can be active at a single time.
AsyncTask handles the threading for you.
In your case, AysncTask has one benefit, that when multi-user (other word, multi connection) connect to database, AsyncTask will do in serial. (But you should notice, this might change through android version, for example: at Donut, they will do together, but in Honeycomb to now, serially)

first android service

I creating a small application that will basically use a background server to send data over HTTP. I dont know how to create services. Secondly there will be a couple of activities in my application. I want the activities to display a Context Menu when data becomes available. How can i do both. I have search for a while but the code i keep getting dose not seem to run on 1.6 api. How can i create the service and how can my activities listen to updates so that when a update is available they display a message.
NOTE: I do not need help on the HTTP part and the server part only creating the service and my activities listening to updates.
Kind Regards,
Give the Service docs a very good, thorough read.

Categories

Resources