engvidal Member Licensed User Longtime User Jan 5, 2018 #1 Hi I have a very simple app that when opened connects to an mqtt broker, and each data received is appended to a multiline editText. It runs ok, but.. If I go to sleep or other app, when I return, the mqtt connections was lost and no new data received. How can I convert it to a service, so it continues receiving data and appending to edittext ?
Hi I have a very simple app that when opened connects to an mqtt broker, and each data received is appended to a multiline editText. It runs ok, but.. If I go to sleep or other app, when I return, the mqtt connections was lost and no new data received. How can I convert it to a service, so it continues receiving data and appending to edittext ?
Peter Simpson Expert Licensed User Longtime User Jan 5, 2018 #2 'appended to a multiline editText', what sort of data is it, why EditText need more information. In a lot of cases you can just copy most of the code over and with a few tweaks it will work. What sort of data are you receiving and sending? Upvote 0
'appended to a multiline editText', what sort of data is it, why EditText need more information. In a lot of cases you can just copy most of the code over and with a few tweaks it will work. What sort of data are you receiving and sending?
engvidal Member Licensed User Longtime User Jan 6, 2018 #3 Hi. If simplicity is the key what matters the data and usage ? I just want that my app continues receiving data while in background, and do not "clear" the edittext when returns to the main activity, just like message text, whatsapp, and others. Upvote 0
Hi. If simplicity is the key what matters the data and usage ? I just want that my app continues receiving data while in background, and do not "clear" the edittext when returns to the main activity, just like message text, whatsapp, and others.
NJDude Expert Licensed User Longtime User Jan 6, 2018 #4 engvidal said: Hi. If simplicity is the key what matters the data and usage ? I just want that my app continues receiving data while in background, and do not "clear" the edittext when returns to the main activity, just like message text, whatsapp, and others. Click to expand... If you use a service you won't be able to update that EditText, what you should do, is keep capturing that data (using the service) and save it to a file, when the Activity kicks in, populate the EditText with the file content. You will have to modify your code to handle that accordingly. Upvote 0
engvidal said: Hi. If simplicity is the key what matters the data and usage ? I just want that my app continues receiving data while in background, and do not "clear" the edittext when returns to the main activity, just like message text, whatsapp, and others. Click to expand... If you use a service you won't be able to update that EditText, what you should do, is keep capturing that data (using the service) and save it to a file, when the Activity kicks in, populate the EditText with the file content. You will have to modify your code to handle that accordingly.
Peter Simpson Expert Licensed User Longtime User Jan 6, 2018 #5 engvidal said: If simplicity is the key what matters the data and usage ? Click to expand... Just having that extra bit of information got you an answer. Anytime the activity resumes, that's when you have to read the file thus updating the EditText. You may want to look into sticky service or better still foreground service. Upvote 0
engvidal said: If simplicity is the key what matters the data and usage ? Click to expand... Just having that extra bit of information got you an answer. Anytime the activity resumes, that's when you have to read the file thus updating the EditText. You may want to look into sticky service or better still foreground service.