Hi I am developing an app which includes multiple web service calls.
I check the network connectivity using connectivity manager, but some time it shows connected although there is no data communication.
I have seen some application will attempt for certain time and then show please try again later.
So instead my application is getting force closed, can anyone please help me out on this one.
Related
I'm currently making an app to exchange data between phone and a bluetooth device. I need this exchange to be in the background so when the device send some data, the app can read it and act from it, whenever the app is active or not.
I already establish some read and write data in the app, but only when it is active for the user. Now I want to take the next level and make the same read and write data but in the background, so the connection between the devices is establish and maintain.
I already know about jobschedule and service. Also, I know that, with the new versions of Android OS, services are killed by some time passed or in Doze mode. Other things I found out was to use threads in the background, but I'm still searching for that. But in the end, I'm still a newbie and maybe I'm missing out some information or I couldn't understand the concepts in their fullness, because I can't see yet how to make a process in background that could react upon a message received from the device or react upon a message received from the phone and create this exchange data.
In all, this raised me a question: how to have this kind of task in the background which read and write data from bluetooth connection between phone and a device? Is it jobschedule? Threads? Or there is one that I'm missing out?
Yet, in SO exist some questions about this related topic, some are outdate about the killing service which android does now, but if this question is a repeated one, please link me one that can solve this problem. I'll be gratefull.
Side note: I would like to know if there is a way to turn this task on and off by some condition or by the user's preference.
EDIT:
Some questions I found:
How to keep Bluetooth connection background? - This one is recent, but I don't know if this service will not be killed by the system.
Android 8.0 background services for bluetooth device - This is recent too and it has in his answer the bluetooth connection could be killed too.
I have an android app that sends and receives information from a vb.net web service. Things are great if there is a solid and fast internet connection but otherwise, everything becomes shaky.
The process goes like this:
1. The app sends information (such as an ID)
2. The web service returns information based on the ID (like a name)
3. The app updates the database within it based on the info sent by the web service.
The problem comes when the internet connection is weak. What happens is the app still sends the information but sometimes the information being received is incomplete or a connection timeout occurs; and the app still goes into step 3.
The app shouldn't be updating the database because the transaction was either incomplete or with errors. Any ideas on how I should go about this?
I was thinking of making sure that the transaction is complete before updating the DB. So the web service also sends a sort of 'complete' signal to tell the app that it's time to update the DB. Is this a good idea or is there a better way to go into this?
As for the connection timeout issue any way to catch that? I've seen a catch for the timeout but are there other alternatives which are better? Also if the connection times out what happens to the data that was sent and received?
Much obliged
I was wondering if it is possible ( it should actually) to run a piece of code every couple of minutes even if the user is using the app. The basic Idea behind this is that the User will take the smart phone with my app loaded in the field and start collecting data, while he is collecting data or playing with other options of the app the phone catches the 3g/wifi zone it will start syncing the data to the server. I keep pushing notifications to the devices from my web service using Google Cloud messaging (GCM) and when it reaches the phone it means the phone is now connected to the internet I run that piece of code which do the sync for me. Would it stop the current activity of the app or I would say do the user will be able to keep collecting data and the sync is also running on the background?. any idea of this type of scenario?
thanks guys.
Anything that communicates with a server is by nature asynchronous in ActionScript (and you can't make it synchronous). So just do what you'd normally do to communicate with the server. Other processing, such as loops over a large collection or drawing a lot of objects, can make the application unresponsive.
Yes it is possible using AsyncTask. And your application will not stop while AsyncTask is running in background.
My android application communicate with web services to download and upload data using AsyncTask. If i receive phone call during communication the application hanged up, else every thing is ok. how i can handle this issue.
Thanks
Try to use a service for these kinds of tasks, for fully understanding what happens it is better to take a look at Android's activity life-cycle:
http://developer.android.com/training/basics/activity-lifecycle/
For my app, I would like to have a service running at all times that the app is loaded that will be checking the availability of a network connection, and as soon as it realizes that a network connection is not available, send a message to the loaded activity so that I can replace the content view of that activity with one that simply states "Network Connection is not available". Then when the network connection comes back, have the activity receive another message so it can switch the content view back. I've looked through several posts on services, and would just like to inquire as the best way to go about this. Any tutorials or simple sample code would be awesome too!
Using a Service for that is not really the best solution. Better is using a BroadcastReceiver. You can add one programmatically as shown here, or in the manifest like here.