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
Aug 10, 2010
I have a doubt in Looper. I want to know when we should use Looper. If any good link for more clarification, it would be great.
View 2 Replies
View Related
Jul 14, 2009
I have a thread that does all my rendering code for a game (including animations). I want to be able to communicate with that thread via Messages instead of locking / synchronization. This means that I need to both support a message queue and *also* support my own rendering loop. Normally I would just clear the message queue every frame of rendering so worst case scenario the messages sit on the queue for one frame before getting cleared out. This also gives a bit of priority to messages in that if the queue backs up the rendering will take a back seat until it empties out.
Everything was going fine until I realized that Looper doesn't have a "Clear the Queue" function! I looked at the source code for Looper.loop() and it appears that the code necessary to manually traverse the MessageQueue is protected, so I can't even write the ClearQueue function myself.
Does anyone here have any feedback on how I can have a thread that keeps the MessageQueue clear at the same time as allowing me to peg the CPU rendering as many frames per second as I can?
My current thought is to insert a message into the MessageQueue along the lines of "RenderOneFrame". When this message is popped off the queue I would render one game frame. Before returning from my rendering code though I would push another copy of the RenderOneFrame message back onto the queue. This means any messages added to the queue while I was busy rendering the frame would get processed before the RenderOneFrame mesage and once the queue was "clear" (ie: RenderOneFrame message was back on top) I would repeat the process.
I suspect that this will work, though I am open to suggestions for either a clear or faster method (I'm more interested in clean at this point, but at optimization time I'll be interested in faster if I bottleneck on this code).
View 3 Replies
View Related
Sep 27, 2010
I'm trying to initialize OpenFeint in my game like this:
CODE:...........
Result: 1. OpenFeint initialization sometimes take so song(network actions?). It blocks the main thread. 2. My application remains in onCreate() for too long. 3. My Dev Phone One display ANR(application not responding) dialog prompting me to choose between 'Force Close' and 'Wait' 4. Soon after that, OpenFeint has done its things and my game shows up behind the dialog. 5. Now pressing 'Wait' will dismiss the ANR dialog and I can continue my game properly.
But obviously we don't want ANR dialog. So now I put it in a Thread like this:
CODE:...............
----------------------------------------------------------------------------- Result: Problem solved. Everything seems to run fine now.
I put Looper.prepare() there because my game will crash if I don't. The log message told me to put it there. I put Looper.loop(); there because OpenFeint will not initialize at all if I don't. I've read the doc about Looper but honestly I don't understand what the doc says.
Question 1. The doc also tell me this: ------------------------------------------------- public static final void loop ()
Since: API Level 1 Run the message queue in this thread. Be sure to call quit() to end the loop. -------------------------------------------------- Can anyone explain when & where should I call quit()?
Question 2 What will happen if I don't call Looper.quit()?
Question 3 Let me ask this straight. Am I taking the correct approach? Is there some kind of loop running alongside my game all the time if I do this?
View 5 Replies
View Related
May 8, 2010
I have a thread I use to periodically update the data in my Activity. I create the thread and start a looper for using a handler with postDelay(). In onDestroy() for my activity, I call removeCallbacks() on my handler.
Should I then call handler.getLooper().quit()? Or not worry about it and let the OS deal with it? Or would it just run forever then, consuming CPU cycles?
View 2 Replies
View Related
Feb 9, 2009
I need a message queue in my background thread, so I created a looper thread.
CODE:...................
View 5 Replies
View Related
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
Oct 27, 2009
I ran into some trouble trying to use a Looper inside an AsyncTask (its doInBackground method). Everything works fine until new Tasks are being created by AsyncTask.sThreadFactory, but once I reach the AsyncTask.CORE_POOL_SIZE limit and AsyncTask begins to recycle the threads, sending messages to my looper (created inside doInBackground) results in a MessageQueue RuntimeException: "sending message to a Handler on a dead thread".
The code I tried was:
CODE:....................
View 4 Replies
View Related
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
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
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
May 12, 2010
I am Graduating in Computing Science, and my final project is a complete research in Android's Platform, with a development of an application. I would like to know how can I get the complete documentation, beacause my research is very thorough, and I relly on books and documentation. The current site I am reading about methods and activities, etc is the Dev Guide on developer.android.com. I don't know if is it complete there. But if you know, could you please show me the link, or tell me how to get it?
View 3 Replies
View Related
Jun 5, 2010
just got my desire this morning and i don't really know what i'm doing with it, i've never had a smart phone before. i've set up my hotmail account as the email account on the phone but, call me paranoid, i'd rather not have it on there at all. if i delete the account on the phone will it have any detremental effect on the actual email account?
View 4 Replies
View Related
Nov 9, 2009
Is there any documentation on the Dev Tools app that is incorporated into the AVDs?
View 4 Replies
View Related
May 1, 2009
I noticed WebView seemed to have some new methods I didn't remember from before. Unfortunately I can't tell exactly which ones are new, without actually trying them and waiting for the SDK to catch the mistake.Could the docs please state in which API release a method, class, interface, enum etc was added? This is pretty fundamental to know when trying to figure out how to implement something.
View 5 Replies
View Related
Jun 11, 2010
Where can i find the ddmlib javadoc or sources? I was browsing through the android git repository but was not able to find the corresponding project.
View 2 Replies
View Related
Apr 29, 2010
I'm using Eclipse with the Android SDK. I installed The SDK platform Android 1.6, API 4 using Android SDK and AVD manager, but I can't find the corresponding documentation in the list of the available packages (there's only the doc for the API 7). Where can I find it?
View 2 Replies
View Related
Oct 6, 2009
I have been using the Android documentation for a few days now, and it is quite good and easy to read. Apart from that I noticed that I missed something, and now I found out what it is: Examples and comments.
If you look at the PHP documentation (e.g. http://www.php.net/manual/en/function.substr.php for the PHP substr() function) you will see many syntax-highlighted examples and comments by users.
Of course there are examples in the Android documentation, especially in the Dev Guide category - they just are not at the right place if one searches the reference for a specific method or functionality. What do you think about this?
View 4 Replies
View Related
Mar 21, 2010
Does anyone know if there is documentation explaining the SMS content provider?
View 3 Replies
View Related
Jul 9, 2010
The documentation does not make the interation between onUpgrade() and onCreate() clear.
When implementing onCreate() should this create the database at version 1, assuming that onUpgrade will apply all of the patches to bring it up to version x (lets say version 5 for example)? Or should onCreate build the latest version of the database, and onUpgrade is only used to upgrade legacy clients.
I kind of prefer the first, because it effectively means that the same SQL is executed for everybody. Whereas the second options means that there is a potential for onCreate to build something slightly different to the succession of patches built by onUpgrade.
I can always make onCreate call into onUpgrade, however, this is the kind of implementation detail that should go into the javadocs...
View 3 Replies
View Related
Jul 20, 2009
A small notice here to say I found an error in the documentation, when building a radio button context menu in XML.
On this page, in the Menus section, under 'Elements and Attributes' for the <group> tag. http://developer.android.com/guide/topics/resources/available-resourc...
"checkableBehavior - Whether the items are checkable. Valid values: none, all (exclusive / radio buttons), single (non-exclusive / checkboxes)"
This should actually be the other way round: * all (non-exclusive / checkboxes) * single (exclusive / radio buttons)
View 2 Replies
View Related
Jun 23, 2010
I'm trying to find some official android documentation that discusses sleep mode, with a focus on issues that might be of relevance to app developers. For example, things like:
1. What causes a device to enter / exit sleep mode?
2. How are running processes impacted when the device enters sleep mode? (I believe they continue to exist, but don't execute because cpu activity is suspended. When the device wakes up execution picks up where it left off?)
There is some good info in the API docs for PowerManager and WakeLock, but nothing there that explicitly states what I have assumed in point 2 above. Are the above issues (and any other relevant issues) documented anywhere?
View 3 Replies
View Related
Jul 24, 2009
Is there a poster showing all the class and methodes offered by the android SDK and their inter dependence?
View 2 Replies
View Related
Aug 26, 2009
I was thinking, wouldn't it be great if all the android reference documentation was in the pages section of this Google Group, i.e. stick everything in here:
http://developer.android.com/reference/packages.html
In here: [url]
View 8 Replies
View Related
Oct 6, 2009
Can someone point me where the documentation of window manager is present?
View 4 Replies
View Related
Apr 8, 2010
I've been looking around for this for a long time but can never seem to find it in the Android documentation. There's all sorts of advanced things I see, but I can never find any solid documentation - there's the shapes package, but it provides no insight on how to use them in xml. The best I can do so far is finding other people's examples.
Is there some magical documentation that exists for the XML shapes?
View 3 Replies
View Related
Feb 10, 2010
Does anyone know how to integrate with the new Gallery3D app (cooliris android gallery)? I want to launch that app so it shows the thumbnails for only a specific folder.
For example, say my app downloads images from my server and stores them in a folder on the sd-card (/sdcard/myapp/image-cache/someid/*). I'd like to be able to do something like the following:
CODE:...........................
View 3 Replies
View Related
May 26, 2010
On the documentation page "Developing on a Device" http://developer.android.com/guide/developing/device.html there may be two errors in the section "Setting up a Device for Development."
First: To run (not debug) an app on a device, you do not need to set the "debuggable" attribute in the manifest. The documentation implies this is a requirement. It may be a good idea, but, when stepping an absolute beginner through the process of running their first app, this is an unnecessary detour.
Second: The instructions for turning on USB debugging don't mention the Settings activity: "On the device, go to the home screen, press MENU, select Applications > Development, then enable USB debugging."
The first error is more of a quibble, but the second seems to be actual misinformation that may puzzle a beginner, wondering why there isn't an "Applications" item on the Home app menu. In most cases this should go "Settings > Applications > Development > USB Debugging," and the menu key is not involved.
View 3 Replies
View Related
Jul 29, 2010
Is there any documentation on the filesystem used for Android? I'm talking about an explanation of the contents of /dev or /etc, and not YAFFS or whatever.
View 2 Replies
View Related
May 24, 2010
However, the documentation doesn't explain any of the parameters. All of them are pretty obvious except for boolean filter. Does anyone know what it does?
View 3 Replies
View Related