Android :: Calling Looper More Than Once Causes - Sending Message To A Handler On A Dead Thread

Sep 4, 2010

I am using an Executor [fixed thread pool] with my own ThreadFactory that adds a Looper:

CODE:...............

I am running a thread that makes network requests but if the network fails I would like a dialog message to be displayed to the user. This process is rather involving since it requires making AND displaying the request in the UI thread. I can wait for the user's response to the dialog by simply adding a Loop to the network thread and wait for a message to be send from the UI thread. This allows me to encapsulate the network requests in a while(tryAgain) thread. All works well except when the Looper.loop() method is called the second time (after a second network error dialog is displayed) and a message is sent by the dialog (in the UI thread) to the network thread's handler:

CODE:.............

In the AlertDialog instance is an OnClickListener:

CODE:...............

I've checked that the thread is still active with handler.getLooper().getThread().isAlive() which always returns true but it still gives me "sending message to a Handler on a dead thread". How is it that the Message/Handler has decided that the thread is dead? Shouldn't it rely on the .isAlive() method? In the end I am trying to avoid replicating the thread management build into the Android OS .

Android :: Calling Looper more than once causes - sending message to a Handler on a dead thread


Android :: Can't Create Handler Inside Thread That Has Not Called Looper.prepare

Oct 6, 2010

What does the following exception mean? And how can I fix it?
This is the code:Toast toast = Toast.makeText(mContext, 'Somthing', Toast.LENGTH_SHORT);
This is the exception:
D/VVM ( 684): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
D/VVM ( 684): at android.os.Handler.(Handler.java:121)
D/VVM ( 684): at android.widget.Toast.(Toast.java:68)
D/VVM ( 684): at android.widget.Toast.makeText(Toast.java:231)

View 1 Replies View Related

Android :: Android - Can't Handler Inside Thread Not Called Looper Prepare

Sep 30, 2010

I am getting reports of 'Can't create handler inside thread that has not called Looper.prepare()' once I added ScoreNinja to my Android app, and released it to the market. It seems that it isn't happening all the time as the ScoreNinja highscore has lots of entries from users. I have looked on the web for help but there are no clear directions on what to do. I have used the ScoreNinja code exactly as shown on the scoreninja website. BTW If anyone is having problems with ScoreNinja only displaying one score, check to see if the launchmode is not set to 'singleinstance' in your manifest. This fixed it for me!

View 6 Replies View Related

Android :: Way To Know Another Thread's Handler Not Null Before Calling It?

Feb 2, 2010

My program threw a NullPointerException the other day when it tried to use a Handler created on another thread to send that thread a message. The Handler created by the other thread was not yet created, or not yet visible to the calling thread, despite the calling thread having already called start on the other thread. This only happens very rarely. Almost every test run does not get the exception. I was wondering what the best way is to avoid this problem for sure with minimal complication and performance penalty. The program is a game and very performance sensitive, especially once it is running. Therefore I try to avoid using synchronization after setup, for example, and would prefer to avoid spinning on a variable at any time.

View 2 Replies View Related

Android :: Handler Fails To Deliver Message / Run Able To Main Thread

Feb 18, 2010

I have an app with a two threads - main and data loader. When data loader finishes it posts a Runnable object to the main thread (as described in the DevGuide), but it never gets delivered and run. Here's the basic code:

class MyApp extends Application{
public void onCreate()
{LoaderThread t = new LoaderThread();
t.start(); }
private class LoaderThread extends Thread {
public void run()
{ SystemClock.sleep(2000);
boolean res = m_handler.post(m_runnable);
if(res)
Log.d(TAG, "Posted Runnable"); } ............

View 2 Replies View Related

Android :: Looper - Handler Issue

Oct 10, 2009

I'd like to know if Looper can enable handler to handle one message at a time, instead of handling all the messages in the queue together in one blocking call when Looper.loop() is called.

Because the looper sends all the messages in the queue to the handler one after the other in one blocking call, my application displays the ANR message. Instead, I want to be able to handle one single message, one blocking call at a time - the instant it falls into the queue.

The following code illustrates my problem: (pls note the lines referred: 1,2,3,4&5) Question 1: After calling looper.loop in line3, line4 and 5 don't run. Why is this? I tried quit(), but it doesn't help. Question 2: Instead of displaying 0,1,2,3,4 in one blocking call (at line3), I'd like to have 5 different blocking calls for each. Essentially (sorry, if i sound repetitive), I want to be able to use looper in such a way that each time, it ensures only one message gets handled.

Is there a way to do this?

CODE:..................

View 3 Replies View Related

Android :: Communicating With A Looper Thread

Feb 9, 2009

I need a message queue in my background thread, so I created a looper thread.

CODE:...................

View 5 Replies View Related

Android :: Better Looper Documentation - Complete Account Of Looper

Jun 23, 2009

Trying to get my head around the specific ins/outs of the Looper object and how it interacts with Threads. Documentation is rather scant on this topic. This is one of those topics that is obvious to the Android core team, but to the rest of us, it's not so obvious.

Can someone point to better documentation or give a more complete account of Looper:

1. What is looper.

2. How does the Android phone use Looper to coordinate message handling?

3. What do I need to do when I get the "Can't create handler inside thread that has not called Looper.prepare()" message?

4. How do I use LocationManager.requestLocationUpdates with Looper, and why does this call require a Looper object?

View 6 Replies View Related

Android :: Passing Data From Bg To UI Thread Using Handler?

Oct 13, 2010

In Handler, we can pass some data from a background thread to the UI thread like this:

private void someBackgroundThreadOperation() {
final String data = "hello";
handler.post(new Runnable() {
public void run() {
Log.d(TAG, "Message from bg thread: " + data);
}
}
}

If we use the above, we cannot then use Handler.removeCallbacks(Runnable r), because we won't have references to any of the anonymous runnables we created above. We could create a single Runnable instance, and post that to the handler, but it won't allow us to pass any data through:.............

View 1 Replies View Related

Android :: Update UI In Main Activity Through Handler In Thread

May 9, 2010

I try to make several connection in a class and update the multiple progressbar in the main screen. But I've got the following error trying to use thread in android : Code: 05-06 13:13:11.092: ERROR/ConnectionManager(22854): ERROR:Can't create handler inside thread that has not called Looper.prepare() Here is a small part of my code in the main Activity.

public class Act_Main extends ListActivity
{ private ConnectionManager cm;
public void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
// Set up the window layout
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title); }
public void startConnection() { ......

View 5 Replies View Related

Android :: What Difference When A Class Extend From Handler And Thread? - In Framework

Mar 18, 2010

What is the difference when a class extend from Handler and Thread?

As described in developer.android.com
...
Each Handler instance is associated with a single thread and that thread's message queue.
...

Does the thread has no message queue ?

Any benefit for a class extend from Handler?

View 2 Replies View Related

Android :: OpenGL Thread Suddenly Dead? (on Draw Frame No More Called)

Mar 22, 2010

I have a problem with a suddenly dead(?) OpenGL Thread. After an indeterminate time (30 seconds to a couple of minutes) the onDrawFrame of the Renderer simply doesn't get called anymore. I get no exception, no ForceClose, no ActivityNotResponding, no nothing! I can still open the Menu, have another Handler/Runnable-cycle logging out "Alive", etc Recently I introduced some native stuff (physics-library). But I can verify that there is no native problem, as there is obviously no native crash and after the GLThread died, I can still do like: Log.d("Before native call") nativeCall(); Log.d("After native call") Maybe anyone of you experienced something similar to this?

View 4 Replies View Related

Android :: Put Object In Handler Message

Jun 9, 2010

I need to download an image from the internet,in a different thread,and then send that image object in the handler message, to the UI thread.And by the way, is this the most efficient way to pass an object to the UI Thread?

View 2 Replies View Related

Android :: Calling ImageSwitcher.setImageURI In A Thread

Nov 21, 2010

I want to display pictures into an ImageSwitcher and change image every 3 seconds. I instanciate a Thread that call the setImageURI(URI) and I schedule it every 3 seconds. It does not update the view and I don't know how to do it. If I call the same code that call the setImageURI() from the OnClickListener of the view it works! Do you know why and how can I make it work?

View 3 Replies View Related

HTC Desire :: Sending Text - Can't Figure Out If Sending A Message Via Facebook Or To Mobile Number

Jun 24, 2010

I have a friend who is added to my Desire's contact list.

1. He is on my Facebook contact. (His facebook pic appears in my Desire contact list)
2. He is my Gmail contact as well.
3. He is added as a 'Phone Contact' as well.

I sent him a text few days ago but don't remember if it was using facebook or my phone (network provider sms) but now when I go in to 'Messages' and send him a message, I just can't figure out if I am sending him a message via Facebook or to his mobile number.

View 1 Replies View Related

Android :: Smack & Xmpp / Handler - Propagate When Receive Message

Oct 7, 2010

connect / login are executed in the same thread of the caller, then are blocking - The packetlistener callbacks are called from smack receiver thread - The sendpacket enqueues the message to a queue. when I receive a message, I need to propagate it. I can use an handler, but it only gets the runnable object. How can I pass the data to the runnable called by the handler? I can't use a local variabile, because if I receive a lot of messages it will be overridden and I will loose some of them. Is it ok to use a queue to feed the runnable? Are there other techniques?

View 3 Replies View Related

Android :: Handler Class And The Timing Of When Its Message Queue Is Emptied

Sep 6, 2010

I was curious about the nature of the handleMessage() and sendMessage() behavior of the Handler class. I want to be able to send message to another thread in such a way that the destination thread can process the message queue when it wants to. It seems, however, that the message is processed by handleMessage() practically as soon as it's sent.

I'm trying to design a game loop thread that does something like this:

CODE:.....

However, I as soon as sendMessage() is called (from the parent/calling thread), the Handler.handleMessage() is processed (in the child/receiving thread), even if the child/receiving thread is blocking in a while loop.

I've seen this problem solved in other games by using a thread-safe list (ConcurrentLinkedQueue). The UI thread just posts events to this queue, and the game loop can remove the events as it seems fit. I just assumed the Handler class was designed for this purpose. It seems it's more intended for asynchronous callbacks to the parent thread.

View 1 Replies View Related

Android :: Passing Array By Calling Activity From A Thread

Jul 23, 2010

I have two activities:

"a" that spawns thread for generating a dynamic array of values inside public void run() function.
"b", graphics activity that will help me draw rectangular pulses based on array values calculated in activity "a" (calculated in a's thread to be precise).

When I am in thread inside "a", how do I pass values of array to activity "b" and
call activity as well.

activity A

CODE:..........

activity B

CODE:..............

View 1 Replies View Related

Android :: Calling StopSelf In Service While Thread Is Running

Sep 14, 2010

Suppose I have code in the onStart() handler of my Service to launch a thread to do some stuff and then call stopSelf().stopSelf() gets called before the thread finishes.What exactly happens?I've tested this out myself and my thread continues to execute until it is finished.Does Android hear the stopSelf() call, but postpone it until the thread is finished?

View 1 Replies View Related

Android :: Call Not Suspend Main (Calling) Thread

Feb 18, 2010

Hi, I've noticed that on android, the call to pthread_join does not suspend the calling thread. I've a number (6) of new thread created using pthread_create and pthread_join is called on each thread. But It does not suspend the main (calling) thread. I believe this relates to the port of pthread lib to android.

View 2 Replies View Related

Android :: Sending Messages Of Different Types To Android Handler

Jul 5, 2010

Is there a way to distinguish between types of messages sent to an Android Handler? For example, I have 2 background threads and would like the handler to recognize which thread a message came from.

View 2 Replies View Related

Android :: Sending Especial Caracters - Pause = - When Calling With ACTION_CALL

Apr 13, 2010

I'm trying to place a call with Intent.ACTION_CALL and a tel uri including pauses and dtmf codes to be sent when the call is established (i.e. tel:+1777777777,,,,,,,,,,5555555).

Android strips all the special characters and place the call to the rest of the uri (i.e. tel:+17777777775555555)

Any workaround?

I'm testing it with HTC Hero (1.5)

View 4 Replies View Related

Android : How To Make Evo Stop Waking Up Dead With Every Text Message

Jun 9, 2010

I picked up the Sprint HTC Evo. This is my first android phone and it's a big upgrade from the windows based HTC Touch Pro that I used to put up with. However, every single notification makes a massive, loud, Beep And I can't figure out how to turn the volume down on it, except to put the phone in vibrate mode. Windows had two volumes: one for system, and one for the ringer. That made a lot of sense.

I think my co-workers are going to get really angry with me if I don't figure this out soon. At first, it was just text messages, but now it's facebook and everything else. Can someone please tell me how to shut up this dumb robot?

I'm not sure what info I need to give you about this, but it's the launch version of the Evo, I did not change anything related to this problem - still using the default applications and such.

View 6 Replies View Related

HTC Desire :: SMS Message Format / Sending Picture Message

Jun 8, 2010

When I send text messages to individual it sends them as plain SMS, this works with my free allocation of texts.When I send text messages to a group (a list of 7 individuals) it sends them as 7 "Picture Messages" - this costs me money!. The message has no pictures and is short?How can I force the phone to not send picture messages?

View 4 Replies View Related

Android :: Trying To Start A Thread Dedicated To Sending And Receiving Data

Apr 8, 2010

I have a main class activity that does the task of sending control to other activities on click of a button. I am also starting a thread in the main class. This thread basically sets up a connection with the server and is active throughout the lifetime of the application.I have two functions in the thread class, send and receive data from server.Therefore, when the other activities need to send/receive data from server, they use those particular functions.First of all please let me know if what I am trying to do is fine as per the architecture of the operating system. If its fine, when I try to run the code, the app crashes and i see a NullPointerException and a RuntimeException in the DDMS log.Could some one please help me out in this or suggest a better way to implement the concept.Also, please be assured that, the other functionality of the code works perfectly fine.

View 15 Replies View Related

HTC Droid Eris :: Show Message In Notification Bar But Text Of Message Will Not Appear In Text Thread

Jun 3, 2010

Sometimes when I receive messages it makes the notification sound and will show message in notification bar but the text of the message will not appear in the text thread. Used to happen every once in a while, now doing it multiple times a day. I use Handcent but I doubt that is the problem because the messages dont show up in the regular messaging either. Just want to see if i am alone with this problem.

View 8 Replies View Related

HTC Desire :: Lighting Up When Message Or Calling?

Apr 22, 2010

When i receive a message my phone doesnt light up, i just get my ringtone/vibration and the little green light. is thier anyway of getting the phone to light up apart from me clicking the lock key at the top, Also when i make a phone call it goes black, how do i chance the Backlight is it to stay on?

View 3 Replies View Related

Android :: Opens At The Oldest Thread Message

Aug 4, 2010

Not sure if this is a common problem, but essentially, in the bundled 'Messages' application for the HTC Legend, the text messages are saved as a thread as standard. But today, for some bizarre reason, when I open a message thread, it opens at the oldest message, whereas before, it would open at the most recent message. I've looked around in the settings, turned my phone on and off, cleared the data, but still can't get it to revert, it's quite annoying to scroll through hundreds of messages to get to the most recent SMS.

View 1 Replies View Related

Android :: Getting Thread ID / Phone# Of An Open SMS Message?

Sep 21, 2010

I am using RunningTaskInfo.topActivity.getClassName() to determine the class name of the activity being viewed by the user. If the top activity is an sms message (the user is texting) then I want to determine either the thread id of the open message or the contact name/ number, either will work! I am able to determine if a message is open by comparing the class name.unningTaskInfo.topActivity.getClassName().equals("com.android.mms.ui.Compo­seMessageActivity") which returns true/false. When it is true I need to get the above information from this "compose message". Any ideas on how I can get this kind of information from an Android OS activity (an sms message)?

View 3 Replies View Related

Android :: Text Message Thread To Email

Sep 24, 2009

is there an app to copy a complete text thread and email?

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved