Using Coroutine for continuous data polling and dumping to UI

All we need is a simple explanation of the problem, which is provided below. My existing Android code uses AsyncTask to continuously poll data from a virtual COM port and dumps data to UI thread by overriding the onProgressUpdate() function. Something like the following: open class ComActivity(deviceID:Int, listener: OnComRxUpdateUI) : AsyncTask<…, …, …>(){ … override … Read more

Cannot get correct SharedPreferences value on onClick

All we need is a simple explanation of the problem, which is provided below. I’m currently making a small app and I’m getting stuck on changing fragments using an onClick listener. I’ve searched the site and could find similar situations, but none of the proposed solutions worked. So, when a user logs in, it sets … Read more

Update TextView fields in onPostExecute()

All we need is a simple explanation of the problem, which is provided below. I’m parsing weather data in AsyncTask’s doInBackground() method and storing parsed data in strings: protected Void doInBackground(Void… params) { … Element element = (Element) list.item(i); if (element.getNodeName().equals(“station_id”)){ String stationId = element.getTextContent(); } else if (element.getNodeName().equals(“observation_time”) ){ String observationTime = element.getTextContent(); … … Read more

TextView isn't updated with JSON Response

All we need is a simple explanation of the problem, which is provided below. I have 3 textviews I’m attempting to update (nameTv, contentTv, publishedTv) with data obtained from a JSON response. When I execute the code shown below the textviews do not update – and when I set a breakpoint at TextView nameTv = … Read more

passing string data from onPostExecute method of AsyncTask to other activity

All we need is a simple explanation of the problem, which is provided below. my question is:In android programming how to pass the string data like name,address that we obtained in onPostExecute() method of AsyncTask to another activity that will receive this string data.for example i want to pass string name, url that i got … Read more

List View should not load onBackPressed

All we need is a simple explanation of the problem, which is provided below. I have Three Activities Main Activity , Order Activity , Order Details Activity. Order Activity has a list view . On click of list View Order Details activity is opened but on back pressed from Order Details Activity the list view … Read more

AndroidHttpClient.execute is returning httpresponse as null

All we need is a simple explanation of the problem, which is provided below. I am trying to access my uri from the below code AsyncTask asyncTask = new AsyncTask() { @Override protected Object doInBackground(Object… params) { AndroidHttpClient httpClient = AndroidHttpClient.newInstance(“”); HttpUriRequest uriGetRequest = new HttpGet(“http://localhost:8080/restsql-0.8.6/res/”); HttpResponse httpResponse = null; try { httpResponse = httpClient.execute(uriGetRequest); … Read more

Implent an AsyncTask callback function returning multiple values?

All we need is a simple explanation of the problem, which is provided below. I’m trying to understand how AsyncTask callbacks work. This is how my MainActivity looks so far: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MyAsyncTask AsyncTask = new MyAsyncTask(arg1,arg2,arg3).execute(); } And this is my AsyncTask class: public class MyAsyncTask extends AsyncTask<String, … Read more

IllegalStateException on AsyncTask

All we need is a simple explanation of the problem, which is provided below. I’m getting a following error when trying to replace a fragment upon receiving a response from AsyncTask: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState The thing is, I get this error randomly upon restarting my app through Android Studio. In … Read more