Questions tagged [android-runonuithread]

This is a way to run the specified action on the UI thread of Android framework.

runOnUIThread is a method of an Android's Activity:
It runs the specified action on the UI thread. If the current thread is the UI thread, then the action is executed immediately. If the current thread is not the UI thread, the action is posted to the event queue of the UI thread.

Useful links

187 questions
1
vote
1 answer

Response error okhttp3. runOnUiThread/Thread

I want to make a request to the server and get a response from it. Next, display in displayWindow. I can’t get a response from the server, I understand that I need to process the UI in a separate thread, I generally do this, but I don’t quite…
1
vote
0 answers

Which Android API classes must have their methods runOnUiThread?

Despite Android being a multi-threaded, some API classes impose a strict requirement of having to only run on the UI thread. For example, All SpeechRecognizer's methods "must be invoked only from the main application thread." The Android…
WebViewer
  • 761
  • 7
  • 21
1
vote
1 answer

Where are variables allocated when referenced within posted Runnables?

My understanding (though it could be incorrect!) is that in Method1(), myInt will be allocated on the stack and then deallocated upon returning from the method. My question is about where myInt will be allocated in Method2() because the method could…
Eric Schnipke
  • 482
  • 1
  • 6
  • 22
1
vote
0 answers

Why Activity.runOnUiThread(Runnable) stops executing the Runnable?

I am programming an EBookReaderApp for Android. It has an automatically scrolling function. The scrolling is implemented in a separate thread to not block the UI all the time. The actual scroll has to run on the UI thread. Therefore I call…
Coding
  • 134
  • 3
  • 10
1
vote
1 answer

The .join() method block UI thread even when called on a new thread

I was writing a kotin application that needs to retrive data online. Using the async(Dispatcher.IO) to get the result from the server and val variable1 = async(Dispatchers.IO) { delay(10000) "I am…
1
vote
0 answers

FindViewById is null after device rotation inside FragmentPagerAdapter

I am trying to modify UI elements that are inside a FragmentPagerAdapter on a ViewPager. Everything goes well until I rotate the device. Then, FindViewById returns null and I can't modify the element. When I rotate the device do I have to keep in…
1
vote
1 answer

OKHttp crashes on when switching Fragments

I have no formal coding education so please let me know if something I did is considered bad coding I am using a bottom navigation view for a train schedule application I am making. One of the options is a nearby functionality - when nearby is…
1
vote
0 answers

How to update UI from Firebase ML FaceDetectionProcessor

I have 2 Files: Camera Activity FaceDetectionProcessor(Firebase MLKit) I have implemented Firebase MLKit for Face detection in my app. It consists of a file FaceDetectionProcessor having an onSuccess method which is called on each camera frame. I…
1
vote
1 answer

runOnUiThread sometimes does not work - why?

I use OkHttpClient to fetch data from server and show it in runOnUiThread event, but the event does not always work Basic logic is that I tap on a button, and OkHttpClient gets a json from the server, parse it and shows me the json data. Don't know…
Lance
  • 21
  • 2
1
vote
3 answers

How to switch TextView between values every 5 seconds

I don't know if using Threads is the practice for what I am trying to achieve so please feel free to amend the code where you wish. I am trying to implement a feature in my app where a TextView switches to 1 value and thereafter reverts back to the…
Adam
  • 203
  • 1
  • 14
1
vote
0 answers

Why is it not possible to see my public activity in an external runnable class?

When the bluetooth connection turns on, I want to start a Therad which is checking for the available devices. When starting this Thread, I want to start an other activity. I created a public method with an intend to start the activity and now I want…
1
vote
1 answer

opencv onCameraFrame attempt to invoke TextView.setText()

When I try to use setText() inside the onCameraFrame, I experience this crash: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference Basically I…
1
vote
3 answers

Using RunOnUIThread causing null pointer Exception After Switching to another Fragment

public class ViewPagerTask extends TimerTask { @Override public void run() { getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (viewPager.getCurrentItem() == 0){ …
1
vote
1 answer

Executing operations on UI thread after delay

I want to implement some operations on UI thread after a delay of a few seconds and have tried this approach - final Handler handler1 = new Handler(); final Runnable r = new Runnable() { public void run() { // operations to do …
dfvc
  • 47
  • 5
1
vote
0 answers

Vars become empty through runOnUiThread (Android)

I have this code: Log.d("1", String.valueOf(c)); runOnUiThread(new Runnable() { @Override public void run() { Log.d("2", String.valueOf(c)); } }); The problem here is that out of the runOnUiThread: the 1 = [1] In in the…
Ron Arel
  • 371
  • 1
  • 5
  • 14
1 2
3
12 13