Android :: How To Pause A Thread's Message Queue?
Oct 7, 2010
I am queuing up a bunch of runnables into a thread via a Handler.post(). I would like the ability to send a note to that thread that it should pause. By pause I mean, finish the runnable or message you are currently working on, but don't go to the next message or runnable in your message queue until I tell you to continue.
View 2 Replies
Mar 30, 2010
I'm writing unit tests for a ListActivity in Android that uses a handler to update a ListAdapter. While my activity works in the Android emulator, running the same code in a unit test doesn't update my adapter: calls to sendEmptyMessage do not call handleMessage in my activity's Handler. How do I get my ActivityUnitTestCase to sync with the MessageQueue thread and call my Handler?
View 2 Replies
View Related
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
Jun 30, 2010
I'm trying to write a game engine in Android, but I don't have much familiarity with threads.
My thread has an attribute, mSurfaceHolder, which holds the surface that I'll be drawing to. The run() method for my thread looks like this:
CODE:.............
STATE_RUNNING represents the state when the activity is in the foreground and the game should be running.
STATE_PAUSED represents the state when another activity has come into the foreground. I'm not completely sure why I need to still draw while it's paused, but that's what I seem to have gathered from the LunarLander example.
What I'm hoping is that while I'm looking at the activity, the game will update and draw (which I test by using LogCat). And then when I go back to the home screen or another activity appears over the top, it will just draw.
Well it does draw and update while I'm watching the activity, so the game loop itself works. But when I leave the activity, it has no effect. Here is the thread's pause() method that is called from the activity's onPause():
CODE:.............
As you can see, to test this method I have logged some messages. Now what I find when I leave the activity is that "Here" is logged, but "There" is not. Now with my limited knowledge of threads (I hardly know what synchronized actually does), I believe this will happen because my thread can't get synchronized with the surface holder. But I don't know WHY it doesn't synchronize. A few seconds after I've left the activity, I see the following warning in LogCat:
Activity pause timeout for HistoryRecord
Any idea why this would happen? There are no problems if I try to start the activity again, the thread just keeps running as it was.
Just discovered something else. The thread pauses just fine if I leave the activity within about a second of having started it. And then it will resume and pause again with no problems at all while the same task is still running. I have no idea why for a short period of time it will work, but if I leave it too long, it won't.
Okay... I fixed it. But I don't think I'm supposed to do what I've done. I've basically removed any synchronization with mSurfaceHolder from both the pause() and the setState() methods (which is used by pause()). No it works as it's supposed to, but I'm thinking the synchronization is there for a reason.
Perhaps the best question for me to ask is this: WHEN should you synchronize a thread with an object by use of a synchronized block? And in this case, what is the purpose of synchronizing with the SurfaceHolder?
View 1 Replies
View Related
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
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
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.ComposeMessageActivity") 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
Sep 24, 2009
is there an app to copy a complete text thread and email?
View 1 Replies
View Related
Jun 16, 2010
I'm writing an Android app. I have a main method, which creates and runs a new Thread using an anonymous inner Runnable class. The run() method, when it's done, calls a method on it's parent class (in the main thread) that calls notifyDataSetChanged() so that the main thread can redraw the new data. This is causing all kinds of trouble (ViewRoot$CalledFromWrongThreadException). The thing is, this method being called from the worker thread is on the class that's created in the UI thread. Shouldn't that be running on the UI thread? Or am I missing something.
View 1 Replies
View Related
Nov 17, 2010
My application launches a thread to query the web for some data. I want to display a Toast message when nothing is found, but my application always crashes. I've tried using the application Context from within the thread, like so: Toast.makeText(getApplicationContext(), "testttt", Toast.LENGTH_LONG).show(); I've also tried creating a Runnable with the Toast call and calling runOnUiThread(runnable) from the Thread (the Toast call in this runnable uses the Activity as the first parameter). Does anyone have any ideas on how to accomplish this?
View 3 Replies
View Related
Apr 19, 2010
I have a problem handling messages in a Thread. My run-method looks like this The problem is that the run-method logs "id from message: null" though "message ID" has a value in the Log-statement. Why does the message "lose" it's data when being send to the thread? Has it something to do with the notify?
View 1 Replies
View Related
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
Mar 5, 2010
I have a simple app and I'm using the AsyncTask to test out a background process, for clearness purposes I've opted to put my AsyncTask in a separate class rather than in an inner class, which where my problems begin, this is my AsyncTask. Code...
View 8 Replies
View Related
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 .
View 1 Replies
View Related
Sep 30, 2010
Am currently running the deFrost FroYo ROM. Everything's fantastic, except...whenever I'm viewing a text message thread, it's slow to scroll through previous messages. Frustratingly slow. Is this a common issue with the deFrost ROM? Or is there something I can change / configure to resolve this?
View 13 Replies
View Related
Nov 29, 2009
I need to have each individual message show up in its own thread not connected to others from same sender. I get fire department texts that need to be read and replied to in non thread format. Otherwise I will be responding to the entire group of messages that could be sent from different users using the same name.
View 3 Replies
View Related
Jul 16, 2010
its 2000+ messages, slows the whole damn phone down, esp handcent and the other msg app. when i try to delete it takes forever and just freezes the phone
View 4 Replies
View Related
Dec 19, 2009
My text thread with my girlfriend is over 4000 messages long, causing significantly noticeable lag-time. I've tried to delete the entire thread with her, but it just freezes up the program and I have to force quit it, and it won't delete the thread. Is there any way to erase all text messages at once, preferably from outside the program?
View 35 Replies
View Related
Dec 2, 2012
I'm in the need of viewing the entire conversation between me and a friend, but since we've sent so many text to each other, I can only scroll up to a certain point, therefore i can't see a lot of messages . What can I do?
View 1 Replies
View Related
Nov 20, 2012
I have an LG lucid.
It's my first smartphone (and touchscreen) Im not too familiar with any of the lingo that Im sure is needed to get my question answered, BUT...
My phone went through an update NOV 13th. When I woke up it was like having a new phone. Im comfortable with it now, but I dont really know what any of the icons that appear in my (text) message threads are.
I had a few red triangles with "!" exclamation points pop up. After some online research I found it to mean a message had not sent. I learned how to delete them and everything has been okay, no icons off to the side of message threads except the attachment paperclip. Until today. I was conversing back and forth with my dad via text. After I had sent my last message to him a blue box with a white 1 (one) in it came up next to the message thread. this box only appears when im in the message home screen, that shows all the message threads, not when that specific thread is open. Along with the box, at the top of the message screen, where it says "messages" with the "+" off to the right hand side there is a blue 1. Im sure its related to the blue box/white 1, considering it was not there prior.
View 14 Replies
View Related
Jun 10, 2010
Does anyone else suffer from slow scrolling? For instance on the list of applications and on a large message thread the scrolling is very laggy and jerky. Surely this shouldn't happen with it's 1Ghz processor?
View 5 Replies
View Related
Jun 6, 2010
I use Handcent for my text messaging and I have one thread I would love to save.But I can't figure out how to do it.I have locked the individual messages of the thread so I don't loose them in my cleanup but I would love to be able to move this entire thread on to my sd card for safe keeping.I checked for an app to do this but didn't fine one so any idea's?
View 3 Replies
View Related
Sep 27, 2010
When using torrent-fu, does the computer (doing the downloading) have to be on? Or can I just use torrent-fu to find torrents when I'm at work, queue them up, and when I get home turn the computer on and it'll start the downloads?
View 1 Replies
View Related
May 5, 2010
I need to store a queue into a DB. I need to be able to insert at the head, and append at the tail. I also need to remove items from the head.
Each item is just a string. I need to maintain a todo list -- high priority items are added to the beginning of the queue. and low priority items are append to the end.
View 2 Replies
View Related
Nov 27, 2009
How can I keep Toast from building up a queue of messages?
I'm working on a board game and I'm sending status messages back to the user with this wrapper function I created for Toast:
CODE:...........
The problem is I've made the flow of game play so simple I can now play it so fast Toast messages queue up, even to the point where they continue to show on the desktop after I quit out of the game. t.cancel() doesn't seem to cancel out the previous message, anyone know what I might be doing wrong?
View 13 Replies
View Related
Sep 29, 2010
Is it possible, with an IntentService, to send another intent to the IntentService from within the IntentService? For example, say my IntentService is processing an Intent which has it write a bunch of data to the database. During this time, several other Intents to write other data may [or may not] have been queued up in the IntentService. Suppose, after processing that Intent by writing the data to the application's database, I want to queue up another Intent to send that data via web service to "the cloud." Perhaps I want to queue this processing in another Intent because sending to the cloud is secondary. Is it possible? Would it cause any problems if the Intent being processed is the only Intent in the queue at the time the IntentService is trying to queue another Intent?
View 2 Replies
View Related
Nov 14, 2009
How can I tell what has and has not bee downloaded? I see options to add to my download queue subscribe...but no option to see what's in the queue or manage what's been downloaded.
View 1 Replies
View Related
Jun 12, 2010
I read somewhere (and have observed) that starting threads is slow. I always assumed that AsyncTask created and reused a single thread because it required being started inside the UI thread.The following (anonymized) code is called from a ListAdapter's getView method to load images asynchronously. It works well until the user moves the list quickly, and then it becomes "janky".final File imageFile = new File(getCacheDir().getPath() + "/img/" + p.image);image.setVisibility(View.GONE);view.findViewById(R.id.imageLoading).setVisibility(View.VISIBLE);
(new AsyncTask<Void, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(Void... params) {
try {Bitmap image;
if (!imageFile.exists() || imageFile.length() == 0) {
image = BitmapFactory.decodeStream(new URL(
"http://example.com/images/"
+ p.image).openStream());
image.compress(Bitmap.CompressFormat.JPEG, 85,
new FileOutputStream(imageFile));
image.recycle();
}image = BitmapFactory.decodeFile(imageFile.getPath(),
bitmapOptions);
return image;
} catch (MalformedURLException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
return null;
} catch (IOException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
return null;
@Override
protected void onPostExecute(Bitmap image) {
if (view.getTag() != p) // The view was recycled.
return;
view.findViewById(R.id.imageLoading).setVisibility(
View.GONE);
view.findViewById(R.id.image)
.setVisibility(View.VISIBLE);
((ImageView) view.findViewById(R.id.image))
.setImageBitmap(image);
}}).execute();I'm thinking that a queue-based method would work better, but I'm wondering if there is one or if I should attempt to create my own implementation.
View 2 Replies
View Related
Sep 11, 2009
I decided to start pipelining input to increase responsiveness in my games. Basically what I do is when the activity receives a Key or Motion event, it sends it to a feed method in the game, which encapsulates it with a time and whatever else I need and puts it in a queue then immediately returns so the UI loop is never held up waiting for long. The main loop later processes the queue, applying the events in it at the appropriate times.
This works great and makes the games snappy, although now I'm starting to miss touch events intermittently. I realized that the events could be recycled objects and that could make them not safe to queue. Is this the case or is it safe to queue them for deferred processing like I'm doing?
View 5 Replies
View Related
Sep 8, 2010
Since I got the original 2.2 update for my Droid, whenever I get a new text message and slide down the notification bar and select the new message, it takes me to the main text message window rather than the actual thread to reply to the person. It is really annoying because it requires an extra step. I figured it would be fixed with the second 2.2 update but it didn't. I called Verizon and they called Motorola and nobody knew of the problem so they shipped me out a new phone and it still does it! I am not sure if I am the only one experiencing this or if its normal. It doesn't do it 100% of the time but closer to 90% probably.
View 1 Replies
View Related