I am creating a project as an app that connects to a device on the network (a specific device) . After clicking the button, which calls AsyncTask
, the button disappears and is not clickable.
I am using class from this library:
The relevant code:
// ... int numAdded = addResultsToDatabase (item) ; If (! DeviceInitTask.isCancelled () & amp; amp; added & gt; 0) {string device = "device"; If (numAdded> 1) {devices = "devices"; } Toast. Mektekst (Nulokldiwais Skenl Rispols Aektivitikis, "Added" + Nanbrtab. Convert (non-aided) + "+ devices, toast. Elananacti_elang). Show (); // device to the list Activity Intent intent = new Intent (NewLocalDeviceScanResultsActivity .This, DeviceListActivity.class); startActivity (intent), end ();} other {// buttons disappear} // ...
the above code OnClickListener
object. addResultsToDatabase
method is as follows:
// ... list & l t; String [] & gt; device = new Arresuchi & lt; & gt; (); for (int i = 0; i & lt; items. size (); i ++) {ScanResultsRecyclerViewAdapter.ListItem items = Items .get (i); if (item. Selected from) (string) [string =] device = new string [4]; device [0] = item.get description (); trim (); device [1] = item .getHost (). trim (); device [2] = item.getLoginUsername (). trim (); device [3] = item.getLoginPassword (). trim (); Deviceskadd (device); }} // Try connecting and get results deviceInitTask = new LocalDeviceInitTask (this, device); DeviceInitTask.execute (); // ...
Just tries to connect to the device, log in using the given username and password, and if successful, auth fulfills token and end is . If it can not connect, then this canal (true)
is called from the work and the toast is shown.
Note that I am checking that logging fails, so numAdded == 0
.
I am being harmed as it is happening due to the code above the code still following in the view. Visual
is. button.invalidate ()
does not work.
The only thing that works so far, obviously, to recreate the activity, but it is not ideal because the user has lost the input and this is not just good practice.
Any advice?
======================
EDIT: So now each device has a different instead of running asyncTask
, all connected is a task, and the results are controlled by instead onPostExecute
task.get ()
. The end result is the same - the button disappears.
=======================
UPDATE: I 've stepped through code in debug mode And found that the button disappears after creating the DefaultHttpClient
object (org.apache.http.impl.client). I am going to step in that class and see if I can know why this happens.
Please check that you try to disable the button within the doInBackground () method of your asynctask If so, you need to disable the code with the onPostExecute () method. Because the UI Thread can not be modified from doInBackground ()
No comments:
Post a Comment