Android Question Lose Activity Socket and String

vercettyDev

Active Member
Licensed User
Longtime User
Hello, I'm working with sockets now to communicate with an activity
But when the user closes the activity or goes to another application I lose the connection in a few seconds.

I was told to create a service.

Does anyone have suggestions of what it can be ??

When I leave something written in an edittext the same thing happens when I open another application, when I go back to the activity it does not have what I left written.
 

Peter Simpson

Expert
Licensed User
Longtime User
Does anyone have suggestions of what it can be ??

When I leave something written in an edittext the same thing happens when I open another application, when I go back to the activity it does not have what I left written.
.
That happens in Android, I believe to get around that issue you should be using StateManager.

You should consider placing socket/data transfer code into a new Service, not starter. Use the starter service to start your new service. Whenever an activity loses it's focus, it will automatically be paused. When the app resumes and the activity is back on the screen again the Activity_Resume sub will be called, that's where you basically restart/restore subs etc.

Enjoy...
 
Upvote 0
Top