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

Android - Null pointer execute() & DialogProgress AsyncTask

I have this code below that basically is the Login process of my app, Why do i have null pointers? Have I implemented it correctly, I have tried to use static for AsyncTask to avoid any memoryleak. Login.java if…
Micheal
  • 11
  • 4
0
votes
0 answers

Is there a "break" method for android.os.Looper?

I'm new to Android development (coming from C/C++, Win32 world). I'm trying to write a single-threaded service that should process various kinds of callbacks (system events, timers). What I need is a (sort of) emulation of a modal message-processing…
valdo
  • 12,632
  • 2
  • 37
  • 67
0
votes
0 answers

HandlerThread null exception - Android

I'm using ThreadHandler in my app this way, public class MessageThread extends HandlerThread { Handler mHandler; public MessageThread() { super("Message Thread"); } public void queueProcessMessage(msgObject mObj) { …
0
votes
3 answers

Refactor to fix architectural error

In a sort-of-working application I see this monstrous code: class SomeUglyClass extends Thread { ArrayList someDataStructure = new ArrayList(); Handler mHandler = new Handler() { // a lot // writing to…
18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
0
votes
1 answer

Loppers Android Error

Hello i have one class in android public class GPSTracker extends Service implements LocationListener { private final Context mContext; // flag for GPS status boolean isGPSEnabled = false; // flag for network status boolean…
Luis
  • 535
  • 2
  • 14
0
votes
2 answers

How i can use Asynctask correctly?

I'm developing an Android application but Asynctask and Looper create to me more problem and i don't understand how to solve this problem... This is my main activity: @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public class MainActivity…
user4252099
0
votes
1 answer

is it possible to quit looper in onReceive method in BroadcastReceiver

Using the following code and when onReceive is fired,am getting the following error Error receiving broadcast Intent { act=com.sample.service.ReminderActivityService flg=0x10 (has extras) } in com.sample.common.UserActivity$1@41c2b4b0 The problem…
hyena
  • 755
  • 1
  • 14
  • 24
0
votes
0 answers

How am I meant to call quit() on a Looper instance once I've called loop()

I'm trying to run a Looper within a separate thread. Essentially the purpose of initating a looper on this thread, is so that it will run the appropriate SoundPool.OnLoadCompleteListener instances. So code wise:…
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
0
votes
0 answers

Android looper loop runs indefinitely on android 2.3.3

The following method call does not terminate within a separate thread in my application. Looper.loop(); I'm not able to diagnose why this occurs. Any suggestions?
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
0
votes
0 answers

Android ListView endless loop both directions

is it possible to make a ListView go endless in both directions? I have 5 items that I want to go like A->B-->C->D->E->A->B... I don't have more than these 5 items, it's a static ListView. Like a circular List with the same 5 items. I have found…
Daniel Storch
  • 327
  • 1
  • 3
  • 15
0
votes
3 answers

Launch a Toast in a static method of a non-activity class

I want to launch a toast message in a static method of a non-Activity class. I read a loto of threads about that, but my situation is a bit more complicated, in particular: I have a service and in OnStartCommand I call with fixed interval a static…
Milioli Luca
  • 309
  • 1
  • 8
  • 20
0
votes
5 answers

Android : Can't create handler inside thread that has not called Looper.prepare()

In my app I have a sercice class that it has this method to show progress dialog when do something : private void openprogresdialog() { new AsyncTask() { ProgressDialog progressDialog; @Override protected…
Elham Gdz
  • 1,015
  • 3
  • 15
  • 31
-1
votes
1 answer

Error while working with getLooper() method in android

I am learning threading and concurrency in Android. I have created a basic program where the main thread sends an interrupt to the worker thread to stop the worker thread's processing. The main thread sends the interrupt after 5 seconds. I have 2…
-1
votes
1 answer

How to know from context values which activity is currently running foreground?

I have a tricky situation. I will try to fully explain it in the best possible way. My app has few activities, say A, B, C. A is the Main Activity and B & C gets called from A. So basically when B or C is running, A will be stopped(onStop()). I am…
NewOne
  • 401
  • 5
  • 19
-1
votes
3 answers

Changing the visibility of views one at a time with a button

I have three views which visibility is currently set to view.setVisibility(view.GONE) and I have a button which I want to change the visibilities to visible one at a time as the user keeps clicking the button. I think I have to use a for loop…
Roach
  • 610
  • 1
  • 8
  • 13
1 2 3
11
12