Android :: Looper - Prepare

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?

Android :: Looper - prepare


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 :: 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 :: Looper Doubt

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

Android :: Looper - LoopOnce

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

Android :: Quitting The Looper

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

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 :: 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 :: Looper Inside An AsyncTask

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

Android :: Prepare The UI From The Webservice

Aug 30, 2010

Playing around with the UI and SQLLite for a while and it looks pretty good to me . We have a requirement that for the App that all the questions would be coming from the server through REST / Web service which would be displayed on the App..

say for e.g if there are 4 questions
1) Enter your Name -- Text Box
2) Did you sleep well last night -- YES / NO
3) How many hours did you sleep - Text Box
4) How did you hear about us -- Drop down

So the requirement is that the Questions would be displayed on the App after doing a SYNC with the server during the SYNC with the server the Questions would be downloaded from the SERVER through REST / Web service..if the phone is not connected then pull the questions from the Database...

These questions are simple questions and they change quite often and we have a similar app which is there for iphone which does this ....

View 1 Replies View Related

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 .

View 1 Replies View Related

Android :: Camera Prepare Fails

Sep 10, 2009

I'm trying to build a simple video recorder for an Android device and I've had limited success and mixed results. It worked once, but now, without changing anything, I'm getting a "Camera is not available" error followed by "prepare failed -2147483648" error.

View 1 Replies View Related

Android :: Prepare Failed In MediaRecorder / Way To Fix

Jul 3, 2009

I am trying to develop an application with Android 1.5(cupcake_r1) for a week but always get an error reported in prepare of MediaRecorder. Can anybody help me to figure out the problem I got in the code below:

PS. In order to figure out the problem, I suppressed the audio recording, and the SDcard is installed in the phone.code...

View 3 Replies View Related

Android :: Api I Can Use To Prepare VCard In Droid?

May 18, 2010

I am preparing a contacts application and would like to support the VCard export. Can anyone tell me if there is any API I can use to create a VCard.

View 4 Replies View Related

Android :: How To Use Other External Cursor / Prepare By SQL Database?

Sep 21, 2009

In the API Demo, there is example on using Simple Cursor Adapter. However, it is using the MediaS tore cursor. Is there any method so that I can use other external cursor prepare by SQL database. I don't know what should I input to the from String.

View 2 Replies View Related

Android :: Media Recorder Prepare Causes Segfault

Mar 28, 2010

I have a situation where my MediaRecorder instance causes a segfault. I'm working with a HTC Hero, Android 1.5+APIs. In the log i see (after the segfault announcement) a register dump and then a numbered list #00 libmedia_jni.so to #18 linker, then a stack trace. My Eclipse won't let me copy the log buffer, but I've done three screen captures that sum it up. If you have time to examine, send me a direct e-mail.<pre><code> if (mRecorder == null) mRecorder = new MediaRecorder(); mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);// mRecorder.setVideoSize(640, 480); // mRecorder.setVideoFrameRate(20); mRecorder.setPreviewDisplay(surfaceHolder.getSurface()); mRecorder.prepare();mRecorder.start(); </code></pre> I've tried other variants, including H263 and 3gp. What else can I do to debug this? Everythin g seems fine up to prepare(). I tried adding the onErrorListener, but it seems to interfere with the MediaPlayer's onErrorListener. I'm using a 4-second beep-count to prepare for auto triggering of the camera, and when I enable the error handler for the MR everything in my handler state machines goes awry.

View 4 Replies View Related

Motorola Droid :: How To Prepare For Android Update 2.2 (Froyo)?

May 22, 2010

Since no one knows when the update is going to come to the Droid. Could be tomorrow or in three months. Its all up in the air. It could happen anytime. Anyways, What do you need to do?

Have a battery near full all the time?
Backup your Aps?
Backup contacts?

Since I am assuming you can get the update without warning, I just wanted to know what steps to take, so I can have no problems with an OTA update.

View 11 Replies View Related

Android :: Need To Prepare KML File For Droid Emulator Control

Jan 21, 2010

I am trying to test my application with location information.
You know the Emulator Control has an ability to load from KML file. (Eclipse -> DDMS -> Emulator Control -> Location Controls -> KML -> Load KML...)
I've prepared KML file using Google earth application with its "Add path". Then saved it by .kml extension and load it on the Eclipse. Eclipse didn't load this KML file.

How to prepare KML file for Android Emulator Control?

View 1 Replies View Related

Android :: MediaPlayer.setDataSource - Fd - Cause IOException: Prepare Failed - Status - 0x1

Aug 6, 2009

What is the preferred way of reusing a MediaPlayer when using resources? My try looks a bit ... too complicated... so maybe I should be happy to see that it didn't work. (I run the Android 1.5 SDK and emulator.)

According to this thread my problem may be a permission problem. http://groups.google.se/group/android-developers/browse_thread/thread...

I get the same error. But in my case it only occurs when I use FileDescriptor!?! The use case differs however, because I use a resource stored in the bundle. I have s0.mp3 safely stored in the project /res/raw and it successfully plays when I use SoundPool or MediaPlayer.create. And the log print tells me I referenced the correct file and stay safely in my package.

I'm sure my way of getting the fd out from a package resource is the problem, I didn't find any other way... But why didn't setDataSource throw the exception instead of a printout? And why on earth is the same resource happily played one way but not the other? Seems like a design flaw rather than a security raise. Should I look in the MediaPlayer.create code to see how they get around the problem or can you help me understand how it works?

This is a test code snippet: (from onCreate of a simple Activity)

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

And the error:

CODE;..............

View 2 Replies View Related

Android :: MediaRecorder Error: Java.io.IOException: Prepare Failed

Sep 8, 2009

I am trying to write a sample program to record the video (say camcorder application). When i run my program using the emulator (I have android-sdk- windows-1.5_r3) I see java.io.IOException: prepare failed. error in logcat output.

Further I can see that I have came across this error when i call MediaRecorder.prepare() from CamcorderActivity.surfaceCreated() But I am surprised to see that activity got launched and I am seeing the camera preview! Again the preview is seen only in half of the screen! Its weird!!!

Further when i do recorder.start() to record the video I get java.lang.IllegalStateException. Yes this is obvious since the prepare () has failed. But the question is why prepare() has failed ?

Here is my code ... package com.example;

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

View 2 Replies View Related

HTC Aria :: AT&T / ROM To Prepare For OTA Firmware Updates

Sep 16, 2010

Looker, lookie, new Aria ROM to allow OTA firmware updates, plus two other bug fixes. I think they are gearing up for Android 2.2, HTC Mobile Phone Support - HTC Aria? (AT&T) - Downloads

View 1 Replies View Related

HTC Incredible :: Prepare Sd Card And Phone Keeps Shutting Off

May 8, 2010

i have no idea why it is turning off i got the phone yesterday. would it be because it is trying to prepare my sd card?it started when i put the card in.

View 4 Replies View Related

Samsung Vibrant :: Want To Prepare Phone To Be Returned To Tmobile / Fix It?

Sep 21, 2010

I've been having an issue with my headphone jack and finally called into Tmobile tech support.
They are going to be sending a replacement phone, so I would like some help on how I can get my current phone ready to be sent back to them.

Currently it is rooted stock 2.1 and has ryanza lag fix applied.
Most of my files are on the SD.

I know I need to unroot, how would I proceed to do that and would unrooting get rid of the lag fix?

View 16 Replies View Related

Sony Ericsson : 1.6 Remains After Upgrade / Error When Reaching Close To End Of Prepare Phase

Nov 1, 2010

Attempted to update to 2.1 , everything appeared to go ok , but after restarting i saw that firmware was still in 1.6 .

The only effect was that my intended apps etc. were gone.

According to SE PC Companion the phone is up to date.

According to the phone's software update a new version of Android is available ..

Using the SE PC Companion to repair ( ca'nt install since aIready have the latest sw according to SE-PCC )

results in installation error when reaching close to the end of the prepare phase.

View 4 Replies View Related

Samsung Behold 2 : How Do I Re-format - Prepare MicroSD Card In Phone Factory Settings

May 18, 2010

I'm considering the possibility of selling my Behold 2 phone and getting something a little better supported (anything HTC, for example). I know how to flash the ROM back to the Stock, but, how do I re-format/prepare my MicroSD card in the phone back to it's factory settings?

And is there anything else that anyone thinks I will need to do in preparation for selling it?

View 1 Replies View Related

Android :: Android How To Send Data From Server To Android With No Request From Android?

Oct 19, 2010

today i meet the problem.i need technic can control the android machine from server.then i want send data from server to android with no request from android.

View 2 Replies View Related

Android :: Android 1.6 - Android - View - WindowManager$BadTokenException - Unable To Add Window - Token Null Is Not For An Application

Apr 14, 2010

I'm trying to open a dialog window, but every time I try to open it it throws this exception:

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

I'm creating it by calling showDialog with the display's id. The onCreateDialog handler logs fine and I can step through it without an issue, but I've attached it since it seems like I'm missing something:

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

Is there something missing from this? Some questions have talked about having this problem when creating a dialog from onCreate, which happen because the activity isn't created yet, but this is coming from a call from a menu object, and the appContext variable seems like it is correctly populated in the debugger.

View 3 Replies View Related

Android :: Android WebView Not Loading A JavaScript File But Android Browser Loads It Fine

Jun 3, 2010

I'm writing an application which connects to a back office site. The backoffice site contains a whole slew of JavaScript functions, at least 100 times the average site. Unfortunately it does not load them, and causes much of the functionality to not work properly. So I am running a test. I put a page out on my server which loads the FireBugLite javascript text. Its a lot of javascript and perfect to test and see if the Android WebView will load it. The WebView loads nothing, but the browser loads the Firebug Icon. What on earth would make the difference, why can it run in the browser and not in my WebView? Any suggestions.
More background information, in order to get the stinking backoffice application available on a Droid (or any other platform except windows) I needed to trick the bakcoffice application to believe what's accessing the website is Internet Explorer. I do this by modifying the WebView User Agent.Also for this application I've slimmed my landing page, so I could give you the source to offer me aid. package ksc.myKMB;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebSettings;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class myKMB extends Activity {
I already have JavaScript on the web browser on, the problem is the web view is acting to different from the web browser.

View 1 Replies View Related

Android :: Resolve The Error - Com.android Internal R Cannot Be Resolved - Using Android File MultiAutoCompleteTextView.java

Aug 15, 2010

I want to implement my own Tokenizer base on the file
"MultiAutoCompleteTextView.java",

but I encounter an error "com.android.internal.R cannot be resolved" when I try to

import "MultiAutoCompleteTextView.java" to my project.

code:.................

I haven't research any solutions to resolve this problem.How to correct "com.android.internal.R.attr.autoCompleteTextViewStyle" my own attr?

View 1 Replies View Related







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