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

Why loop() in Looper class gets called multiple times

I have a simple piece of code which starts an intent but when I debug it passes through various classes and often makes me wonder why these classes get called every time and what tasks are they performing before coming back to normal execution. the…
vikas kumar
  • 10,447
  • 2
  • 46
  • 52
0
votes
1 answer

When does ALooper_pollAll return ALOOPER_POLL_TIMEOUT?

Let's assume, that a couple of file descriptors with corresponding callbacks are added to the looper, and then ALooper_pollAll() is called with a timeout of 1000 milliseconds. Soon after that some of the file descriptors become available and the…
Alexander Solovets
  • 2,447
  • 15
  • 22
0
votes
2 answers

What is the role of the child thread creation handler?

1.I have a problem about creating a handler in a child thread like public class Main4Activity extends Activity { private TextView mTextView; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { …
kai hello
  • 135
  • 1
  • 2
  • 13
0
votes
0 answers

RealmResult not autoupdating

I have a RealmResults object which i am updating but the problem is that it does not get updated in real time. code... Thread syncMessages = new Thread(() -> { final Realm realm = Realm.getDefaultInstance(); ChatManager chatManager =…
Jude Fernandes
  • 7,437
  • 11
  • 53
  • 90
0
votes
1 answer

Not executing onPostExecute() after Looper.loop()

doInBackground() works fine.. code after Looper.loop() will not work. Log not printing after Looper.Loop() and not executing onPostExceute(). I need to wait until method 1,2,3 execute. Exception will occure in method1 if Looper.prepare() not…
Akshay Kumar S
  • 333
  • 3
  • 12
0
votes
0 answers

Recurring Messages when using Toast with an Intent Service

I am working on displaying an Android Toast message from an IntentService. After a bit of research and understanding how Loopers, Handlers and Message queues work, I implemented the solution found here: Toast on an IntentService I find that in…
0
votes
0 answers

How do I stub android.os classes in Android Studio?

I've written a real-time subsystem for Android that I'd like to test on the desktop. I would like to run tests via a command line tool of my creation. The subsystem depends on Android as follows: android.os.Looper android.os.Handler (including…
Joe Lapp
  • 2,435
  • 3
  • 30
  • 42
0
votes
1 answer

Any benefits of using Looper for Producer-Consumer pattern?

In my app there are few threads with while-on-volatile-boolean loops and BlockingQueues for quite simple objects-messages they process (pipelined architecture). Recently I've encountered android.os.Looper class with it's friends, that seems to do…
Pavlus
  • 1,651
  • 1
  • 13
  • 24
0
votes
1 answer

how to stop notification thats in handler thread

I have a custom notification that has four RemoteView TextViews. When onPause() gets called I want to post the notification and then update it every second while the screen is on. When onResume() gets called I want to cancel the notification. So far…
0
votes
2 answers

Handler in Android Project : Thread Safe

I am using Handler in an android project to give a callback to to the main/ui thread. if (mHandler == null) { mHandler = new Handler(Looper.getMainLooper()); } mHandler.post(new Runnable() { public…
0
votes
3 answers

App goes to MainActivity when running class

I am trying to run this script, but somewhere in doInBackground() it's being launched back to starting activity. (What I'm trying to do is scan all available SSID's and check them in database) Here is my code: Button btnHit; TextView…
Silver Boy
  • 113
  • 1
  • 1
  • 8
0
votes
2 answers

Looper.Loop() exception inside invoked method

I am invoking a method: method = (MessageController.getInstance()).getClass().getMethod(data.getString("action") + "Action", cArg); method.invoke(MessageController.getInstance(), "param1"); and the method: public static void errorAction(String…
Rami Dabain
  • 4,709
  • 12
  • 62
  • 106
0
votes
2 answers

Hold calling thread until multiple asynctask finishes

I have a background thread which calls 3 asynctasks to perform tasks simultaneously. The calling thread acts as a Queue for 3 sets of these tasks. So basically I need to call 3 asynctasks simultaneously and once they are completed I want to call the…
0
votes
1 answer

Duplicate looping

Here is my FileObserver code: private void updatecheck() { // Email sync loop mHandler.post(new Runnable() { @Override public void run() { if (Looper.myLooper() == null) { Looper.prepare(); …
0
votes
1 answer

Unable to obtain GPS co-ordinates in background (Using Handler)- Android

I am trying to obtain GPS co-ordinates via a handler. Below is the code : final Thread ObainGpsBackground = new Thread(new Runnable() { @Override public void run() { try{ String…
TechFrk
  • 185
  • 2
  • 2
  • 15