Android Question HttpUtils2 occasionally reposts multiple times (to a specific device)

mc73

Well-Known Member
Licensed User
Longtime User
It's been a long time since I first saw this behavior, to a web server, using php to handle requests.
Now, I have a case, where a client (android) is connected to a jetty server (b4j), and occasionally it posts multiple times the same request. Honestly, I don't suspect httputils, since it's working great in many many instances, so my question is whether there could be something wrong with this specific device. Any advice is welcome
 

mc73

Well-Known Member
Licensed User
Longtime User
No logs. Posts are written to a db. One post was inserted around 50-60 times, same timestamp. Client informed me that during posting, she noticed that android 's screen was blinking!
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
You can store the last timestamp in the user session (on the server) and if the new request has the same timestamp just ignore it.
This can be done, by filtering the unique id sent from the terminal, since the timestamp can be the very same for two posts which are valid. In fact, I will soon do this, thank you.

However it's getting really weird! Today, client remembered, that apart from server showing 50-60 entries of the same item, the printer got the same 50-60 entries printed as well!
My app is using an activity, activity then sends data to a service, and then the service a) sends data to server and b) AFTER we have a successful return from server, we send the job to the printer.
This may mean that somehow I have multiple jobs indeed. BUT, I have a copy of the db and it shows something even stranger. I see that while most of the duplicate posts are identical, from the 50-60 entries, there are some 5 of them which differentiate in a specific field!!! This field is a process global var, which under no way can change while user sends data. Somehow, to me, the key is in the fact that android's screen was blinking for some time. That is, perhaps my service restarts (?), but even if so, how on earth this var can change???
This all, brings me to the point to suspect the particular device, though I don't quite understand how it can go crashing and repeating actions on each own. Any ideas?

PS: Needless (?) to say, that this app is up for 3 years now, 500+ installations, many of them under very heavy usage, and I never had such kind of a report before.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
If the screen was blinking then your activity was restarted many times.
Sure. The only way I can think it's being restarted, is after exiting it, the sending service is restarted multiple times and returns data to the closed activity (by callSubDelayed), and then initiating a new service instance. This service, can be restarted if for e.g. httputils is restarted and returning multiple returns to the original sending service. I really can't see how this is possible, unless it's a failure with network and/or the device. I'm thinking about the http trying to resend the request, still, how could it return multiple returns?
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
A single request will never call JobDone multiple times.
Of course. But what if somehow the same request is restarted, by - and this I don't know how - the service? I remember, Erel, I had this curious behavior once or twice, two years ago, with a php server. Then, I took the log, and nothing bad was really shown, except that the original service for the request, was restarted multiple times, without something in my code doing this. It didn't happen again though, when I changed my testing device. I really don't know what's going on...
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Are you sending a request from Service_Start?
In service_start I'm calling a routine to save data locally, and this routine calls another routine to send data. So, yes, the process starts from inside the service_start
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
It is better to use Service_Create. Service_Create will only be called once when the service is created (unless it is later destroyed). Service_Start can be called multiple times. Specifically it is called whenever a matching intent is sent.
Ah, great! Still, I remember I had to move some calls to service_start, but can't remember why Anyway, I'll try this, thank you.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…