Questions tagged [android-looper]

In Android, a Looper is used to run a message loop for a thread since threads by default do not have a message loop associated with them.

Class used to run a message loop for a thread. Threads by default do not have a message loop associated with them; to create one, call prepare() in the thread that is to run the loop, and then loop() to have it process messages until the loop is stopped.

Most interaction with a message loop is through the Handler class.

This is a typical example of the implementation of a Looper thread, using the separation of prepare() and loop() to create an initial Handler to communicate with the Looper.

class LooperThread extends Thread {
    public Handler mHandler;

    public void run() {
        Looper.prepare();

        mHandler = new Handler() {
            public void handleMessage(Message msg) {
                // process incoming messages here
            }
        };

        Looper.loop();
    }
}

More Info

167 questions
0
votes
1 answer

I am new to android and Realm I need to implement a database listner with realm. How can i do it with kotlin?

fun createListner(toDoList:SwipeMenuListView,arry:ArrayList){ toDoList.adapter = TodoListAdapter(cont,arry) this.passData(toDoList,arry) swipeList(toDoList,arry) } This above is the where I update my ListAdapter…
0
votes
1 answer

The current thread must have a looper

Here I am trying to add a view over main_layout for a specific time duration, for that I write this main_layout.addView(linearLayout) Handler(Looper.getMainLooper()).post(Runnable { val timer = Timer() timer.schedule(object :…
Devraj
  • 1,479
  • 1
  • 22
  • 42
0
votes
1 answer

How do I get the Looper for a new Thread that I just created?

I'm creating a thread to handle a request. In the thread I must call Looper.prepare() which is require by some other functionality it is using, and then I call Looper.loop(). But when the connection for the request is closed, I get a callback in…
Michael
  • 9,060
  • 14
  • 61
  • 123
0
votes
2 answers

How to set up a Handler/Looper to call requestLocationUpdates in a Service callback

I've got a service that instantiates a web server using com.koushikdutta.async.AsyncHttpServer. Inside a callback, I need to instantiate a class which is calling requestLocationUpdates on LocationManager. But this is causing an exception: Can't…
Michael
  • 9,060
  • 14
  • 61
  • 123
0
votes
0 answers

Looper MessageQueue stops being processed after a while

I am working on an app that unfortunately has to mix the logical work with the UI a little bit. Because of that, I am calling runOnUiThread(...) quite often. That works fine until after a while, the posted Runnables just aren't processed any…
Finni
  • 429
  • 5
  • 17
0
votes
0 answers

WeakReference to MainActivity to use inside a static Handler

I have a static Handler in my MainAcitivty. I have "handleMessage" as well but am not able to access Objects like TextView which belong to MainActivity. Is WeakReference the way to go here in order to access these objects from within the…
0
votes
1 answer

how to timeout requestLocationUpdates?

When no GPS fix found, the code is getting stuck indefinitely in the looper. I want to add a timeout so that if there is no GPS fix found, it should come out of the looper and execute the remaining part of the code. I will really appreciate if you…
0
votes
1 answer

Why still calling nativeWake() when the thread not blocking?

Why still calling nativeWake() when the thread not blocking? when a thread call the method enqueueMessage(), which means the thread is not blocking, but Why still calling nativeWake()? MessageQueue#enqueueMessage boolean enqueueMessage(Message msg,…
0
votes
1 answer

I cannot figure out how to get past this Looper.prepare() error when trying to use my custom Android ArrayAdapter

I have created a custom ArrayAdapter so I can filter the results to my AutoCompleteTextView: public class AutoCompleteCountryAdapter extends ArrayAdapter { private List countryListFull; public…
Brian
  • 1,726
  • 2
  • 24
  • 62
0
votes
1 answer

why junk data receiving in Looper.getMainLooper())

Receiving proper data outside of Looper.getMainLooper()) I could not able to understand,why Junk data receiving inside of Looper.getMainLooper()). public class A1Service extends PresentationService implements Runnable { switch(dataId) { …
0
votes
1 answer

branch.io loadRewards - Can't create handler inside thread that has not called Looper.prepare()

I am using branch.io for referrals. When I make a call to load the rewards using loadRewards(), I get the following exception: Fatal Exception: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() …
Swapnil
  • 1,870
  • 2
  • 23
  • 48
0
votes
1 answer

Unable to fix exception in Looper.java

I have an app created for the purpose of auditing the hotels. This is a method in it. This method is supposed to save the answers that the auditor enters while using the app. The method is: private void loopQuestions(ViewGroup parent) { …
0
votes
1 answer

In Android can I set the Handler(looper) priority?

I have this setup where a Progressbar show indetermient progress. Then I have this background Threads that surface on the main looper thread into a RecyclerView adapter. The Threads simultaneously report progress to the Progressbar that have it´s…
Tord Larsen
  • 2,670
  • 8
  • 33
  • 76
0
votes
0 answers

What's the function of looper for constructor of Handler?

I am confused on the function of Looper in the Handler. I have some code like this: snippet1: mThread = new Thread(){ @Override public void run() { Log.d(tag, "thread 1 current thread:" + Thread.currentThread()); //if(null ==…
twlkyao
  • 14,302
  • 7
  • 27
  • 44
0
votes
0 answers

Can we pass messages to UI thread without reference to UI handler?

I have a complex class system, with many classes trying to update UI elements, so i searching for most efficient way to achieve this.In my opinion, using handler is the best solution (if you know the better way - please share it ). But there is some…