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
302
votes
3 answers

Warning: This AsyncTask class should be static or leaks might occur

I am getting a warning in my code that states: This AsyncTask class should be static or leaks might occur (anonymous android.os.AsyncTask) The complete warning…
Keyur Nimavat
  • 3,595
  • 3
  • 13
  • 19
16
votes
2 answers

How to run code after a delay in Xamarin Android

I'm trying to show some code after a delay in my Android app. The Java code for doing this is something like this: new Handler().postDelayed(new Runnable() { @Override public void run() { // your code that you want to delay here …
amitairos
  • 2,907
  • 11
  • 50
  • 84
11
votes
5 answers

runOnUiThread is not calling

localChatManager.addIncomingListener { from, message, chat -> Log.v(TAG,"listener") //You can't modify views from non-UI thread. this@chatActivity.runOnUiThread { object :Runnable{ …
Ankur Khandelwal
  • 1,042
  • 3
  • 19
  • 40
11
votes
3 answers

Difference between android runOnUiThread and simple code in java

I am a beginner in android application development.I am working with threads in android.I have read about a runOnUiThread which run code on main UI(if i am not wrong?i guess.). My question is what is the difference between normal code on main UI and…
Mohit Gaur
  • 355
  • 1
  • 3
  • 22
10
votes
4 answers

How get result to UI Thread from an android kotlin coroutines

I didn't understand how kotlin coroutines work. I need to do a long work on an asynchronous thread and get the result on the UI Thread in an Android app. Can someone give me some examples? For example private fun getCountries(){ …
8
votes
1 answer

How to unit test code wrapped in `runOnUiThread`?

I have a function that calls runOnUiThread as below fun myFunction(myObject: MyClass, view: MyView) { // Do something view.getActivity().runOnUiThread { myObject.myObjectFunction() } } I want to UnitTest myFunction to ensure the…
Elye
  • 53,639
  • 54
  • 212
  • 474
7
votes
1 answer

runOnUiThread without Activity

I have created an java class in android studio and I want to use runOnUiThread() in this class. Can I run runOnUiThread() thread without Activity.xml in Android? If Answer is yes? than how?
nisarg parekh
  • 413
  • 4
  • 23
6
votes
2 answers

runOnUiThread(new Runnable() { punctuation (token) issue

Somehow it doesn't work, according to me it should be this: public void Splash(){ Timer timer= new Timer(); timer.schedule(new TimerTask(){ MexGame.this.runOnUiThread(new Runnable() { public void run(){ …
Diego
  • 4,011
  • 10
  • 50
  • 76
5
votes
2 answers

React Native Android Bridge Error: Must be called on main thread

I am using the Sumup SDK to create a bridge to React Native. Most of the hard work is done but I am trying to call a specific function to wake up the card reader before a transaction is processed. The original code I had was this: @ReactMethod …
James
  • 51
  • 1
  • 5
4
votes
0 answers

Android runOnUiThread and performance

My Android App is an Open GL ES 2.0 App. For one particular scene, I am overlaying a few textViews on top of my GL Surfaceview along with the some OpenGL textured quads. I need one of my textViews to 'flash' - I'm targeting Gingerbread, therefore,…
Zippy
  • 3,826
  • 5
  • 43
  • 96
4
votes
1 answer

Xamarin.Android Timer to update the UI - runOnUiThread

I'm developing a Xamarin.Android app that references a portable class library with viewmodels. MvvmCross is being used. I need a Timer that updates the UI every time it "ticks". I just can't seem to get it to update the UI. It is performing the Tick…
Ben
  • 259
  • 1
  • 3
  • 14
4
votes
5 answers

sendBroadcast thru UI or non-UI thread?

Is it better (for performance) to send a broadcast (ACTION_APPWIDGET_UPDATE in my case), in a separate thread than the UI thread (a runnable)? Or is it acceptable practice to do so on the UI thread?
Mehmet K
  • 2,805
  • 1
  • 23
  • 35
3
votes
0 answers

Proper way of handling listener callbacks that happen on background threads

In Android using Java, when using a listener callback method that can be called from multiple threads according to the documentation, is there any harm in forcing it to run on the main thread by surrounding the method body with runOnUiThread like…
Nerdy Bunz
  • 6,040
  • 10
  • 41
  • 100
3
votes
2 answers

android BroadcastReceiver called twice

i am working on chat project what i did here is service with the connection staff and i set a broadcast receiver to get the data from the service this is the receiver code mMessageReceiver = new BroadcastReceiver() { @Override public…
3
votes
4 answers

RecyclerView blocking ui thread during updates

There are more than 200 items in my list. RecyclerView is updated regularly (Every 10 seconds) . RecyclerView blocking ui thread for few seconds during updates. I'm using notifyDataSetChanged method for refresh recyclerview. Is there another way…
1
2 3
12 13