Questions tagged [android-thread]

147 questions
1
vote
1 answer

RunOnUiThread can't access Message directly

I'm sending a message to a Handler which is associated to it's own Thread. In the handleMessage method I try to update the UI with the content of the message using runOnUiThread. This works fine if take the message obj parameter from…
Logarith
  • 690
  • 1
  • 7
  • 27
1
vote
1 answer

Threading Error

I get some error. I really couldn't solve it today :( I get error after set ID data to lblID in FillData() method. It sets ID data properly but lblTitle and lblPrice always returns error like "Only the original thread that created a view hierarchy…
thrashead
  • 337
  • 1
  • 3
  • 16
1
vote
1 answer

Executors reused in other class is the best practice?

I am using ExecutorService executor = Executors.newFixedThreadPool(1); in Main activity for networking stuff. My question is, for other class or activity i have to use this executor object or i have to do shutdown this Executor at end of my main…
Cyrus the Great
  • 5,145
  • 5
  • 68
  • 149
1
vote
0 answers

Is there any limit of Handler creation in an activity android?

We can create Handler in an activity as many as we want using new Handler() and then use those handler to post and remove Runnable anonymous classes. We can also use HandlerThread in an activity for handling task in another thread. But how much…
0xAliHn
  • 18,390
  • 23
  • 91
  • 111
1
vote
1 answer

Sound plays earlier than view is changed

I am creating a piano app in android studio: I have an on click listener for my play button which when pressed is supposed to make the record and play buttons invisible and the stop button visible while the recorded sounds are playing. Play…
1
vote
2 answers

Calling Looper.prepare() in a thread's constructor results in RunTimeException

I have a class which extends to Thread as follows - public class ThreadTest extends Thread { private Handler handler; private Runnable runnable; public ThreadTest(Runnable runnable, Handler handler) { this.handler = handler; …
krtkush
  • 1,378
  • 4
  • 23
  • 46
1
vote
1 answer

Android NativeActivity: AttachCurrentThread JNIInvokeInterface is not a structure or union

I am using the NativeActivity from C. My goal is to get a reference to a JNIEnv so I can make further Android calls. Going by the examples I have gathered on the Android documentation and Stackoverflow, I keep seeing…
1
vote
0 answers

How to Run AsyncTask.? only works first time

I have upload to image from device Sd card to FTP server using android studio.when i upload the image,image successfully uploaded on first time and 2nd time uploaded the another image the "new AsyncTask()" not call what i do some one help me what…
1
vote
2 answers

Cannot access database on the main thread - Android Room - Using ThreadPoolExecutor

I'm getting that famous error "Cannot access database on the main thread since it may potentially lock the UI for a long periods of time" But from what I understand, I'm not accessing the database in main thread since I'm executing the call inside a…
1
vote
2 answers

Android: Simple thread example crashing

I'm trying to find out how does the working thread in Android Studio work. I created a simple example but I'm struggling with following issues, the java code is: package tlacitko.button; import android.support.v7.app.AppCompatActivity; import…
Lucie P.
  • 603
  • 1
  • 5
  • 6
0
votes
0 answers

Android synchronized block causing ANR issue

Following is my code @NonNull private T readLocalResource() { synchronized (this) { if (data == null) { String resourceAsString = sharedPreferences.getString(key, null); if (TextUtils.isEmpty(resourceAsString)){ …
0
votes
0 answers

Android draw on canvas with another delay than thread

I have a Thread which draws my stuff with specific delay. Now I want to add to this stuff also method that will change drawn bitmap between bitmap[2]. This change bitmap delay I want to be different than thread's (thread's 33ms, bitmaps change…
0
votes
0 answers

How to stop long running disk operation in Thread or Coroutine in Android?

Let's say we have this pseudo code in Android: fun writeData(fd: File, data: Data) { timeout (1000) { //max running time is limited to 1000ms val operation = create thread/coroutine { // Thread or Coroutine Os.write(fd, data)…
t0m
  • 3,004
  • 31
  • 53
0
votes
1 answer

How to make an Image Getter in a RecyclerView using fromHTML more efficient?

I'm using fromHTML to load HTML text into a TextView inside a RecyclerView element. This does work, however it is incredibly slow as the images are being loaded from a URL and when the adapter is set or updated the app freezes up or crashes and I…
0
votes
0 answers

alert dailog is not visible when user came to application from backgroud

I am downloading a file from the Azure storage and showing an alert dialog to a user with a progress bar. I am downloading the file from the background thread and showing the alert on the UI thread. When I start downloading the file it is showing…