Questions tagged [android-threading]

Android Multi-threading is the ability of an Android app to perform work concurrently or asynchronously by utilizing multiple concurrent streams of execution (generally referred to as threads).

90 questions
61
votes
6 answers

Difference between AsyncTask and Thread/Runnable

I have question which puzzles me. Imagine I wanna do something in another thread, like fetching GPS/Location stuff, which as recommended in the SDK documents, must use a background thread. So here is the question: What's the difference between…
6
votes
2 answers

Android CoroutineScope Auto Cancel after It Finishes

I want to know whether coroutineScope will be auto-canceled after its work is finished. Say I create a coroutineScope in a custom class Rather Than ViewModel class or Fragment / Activity class: class MyClass { private val backgroundScope =…
4
votes
2 answers

how to resolve FATAL EXCEPTION: DefaultDispatcher-worker-4

I have written a new usecase to communicate to api which uses Flow, I am guessing I am not handing the threading properly in the Usecase between Main thread and IO thread, This is the error I get -01-18 02:20:40.555 26602-26870/com.xxx.xx.staging…
BRDroid
  • 3,920
  • 8
  • 65
  • 143
3
votes
1 answer

Android View Binding in Thread error NullPointerException

I've switched my code to View Binding but now I've got a problem with updating UI in a thread. The code worked OK in synthetic syntax. I'm getting error: java.lang.NullPointerException at HomeFragment.getBind(HomeFragment.kt:25) at…
Artyum
  • 169
  • 2
  • 13
3
votes
0 answers

Extract video frames on Android with ExtractMpegFramesTest and running a computationally intensive function instead of saving as images

On Android, I want to extract all frames of a video and run an object tracking function from boofcv on each frame. Therefore, I am using the ExtractMpegFramesTest example and slightly adjusted it to run the tracking on each frame instead of saving…
3
votes
1 answer

How to make a new thread, Android Studio?

I have the following fragment class: public class fragment1 extends Fragment { private TextView bunz_count; private TextView money_count; private Bunz bunz; private Handler handler; int delay = 1000; View view; @Nullable …
Evan
  • 1,892
  • 2
  • 19
  • 40
2
votes
1 answer

Kotlin - Achieving Executors.newSingleThreadExecutor behaviour using coroutines

Executors.newSingleThreadExecutor queues the tasks registered to it and then executes them sequentially. The following code: val singleThreadedExecutor = Executors.newSingleThreadExecutor() (0..10).forEach { i -> singleThreadedExecutor.execute…
2
votes
0 answers

Custom Keyboard:The specified message queue synchronization barrier token has not been posted or has already been remove

I have made a custom keyboard, recently it crashed with this log randomly, 2020-07-03 16:30:53.529 11538-11538/com.nisarg.nboard E/AndroidRuntime: FATAL EXCEPTION: main Process: com.nisarg.nboard, PID: 11538 java.lang.IllegalStateException:…
2
votes
1 answer

How to boost to load multiple images from web to ImageViews

To load several images from a website, the following code was written. public void connectImgtoView(final int max) { new Thread(new Runnable() { @Override public void run() { URL url = null; …
2
votes
2 answers

Android: Another thread is making the UI unresponsive?

I'm starting a new thread from my activity, this thread does a 10 second operation and then reports back to the UI with runOnUiThread() During the 10 second operation, the UI becomes unresponsive and does not respond to any user interaction. In this…
Kes Walker
  • 1,154
  • 2
  • 10
  • 24
2
votes
1 answer

Why does this code give this output for the thread's priority?

I have the following code onCreate() Log.d(TAG, "Setting priority background"); Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); Log.d(TAG, Thread.currentThread().getId() + ": " + Thread.currentThread().getPriority()); Log.d(TAG,…
Jim
  • 3,845
  • 3
  • 22
  • 47
2
votes
2 answers

How to reuse Android-Handler after removing callbacks

I have a service in which I'm using a handler for getting the time of mediaplayer every millisecond. But, when my service is not bound to any activity, i want to remove the callbacks from the handler in onUnbind(); method of the service. When the…
Nasib
  • 1,173
  • 1
  • 13
  • 23
1
vote
0 answers

How to stop all native threads when Android app is backgrounded?

My video game is based on NativeActivity and has a lot of C++ threads. I'd like all those threads to pause like they do on iOS when my app is backgrounded. There are simply too many threads to chase them all down at random times. Does Android…
Bungles
  • 1,969
  • 2
  • 25
  • 54
1
vote
1 answer

How to communicate with a worker viewmodel in Martin's Clean Architecture

In my application I have a socket UDP server which listens to broadcast messages and notifies the UI about the message with an interface to update the recyclerview to add the message. I used to use a thread to listen to the port, but I'm trying to…
1
vote
1 answer

How does Object.notify() work with Object.wait()?

I am trying to track a resource which behaves in an asymmetric manner. That is, it responds immediately to a start() request, but finishes processing a cancel() request at a significant delay. For this purpose, I created an AtomicBoolean flag, with…
WebViewer
  • 761
  • 7
  • 21
1
2 3 4 5 6