application freezing with Looper

by Pedro Cristov茫o » Tue, 20 May 2008 02:55:28 GMT


Sponsored Links
 hi all.

my android application freezes when using the Looper.prepare() ->
Looper.loop() -> Looper.myLooper().quit() sequence. here's the code
where it blocks:

public void endData() {
               String result = new String(baf.toByteArray());

               Looper.prepare();
               Toast.makeText(myActivity, result,
Toast.LENGTH_SHORT).show();
               Looper.loop();

               Looper.myLooper().quit();

}

any idea of what the problem might be?

thanks in advance,

pedro cristovo.
--~--~---------~--~----~------------~-------~--~----~



application freezing with Looper

by Romain Guy » Tue, 20 May 2008 02:58:43 GMT


 Looper.loop() creates a loop in which your application gets stuck. Why
are you using a Looper here?






-- 
Romain Guy
www.curious-creature.org

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


application freezing with Looper

by Pedro Cristov茫o » Tue, 20 May 2008 03:44:46 GMT


 thanks for your reply, romain guy.

if i don't use the Looper i get this error: "Can't create handler
inside thread that has not called Looper.prepare()."




--~--~---------~--~----~------------~-------~--~----~



application freezing with Looper

by Romain Guy » Tue, 20 May 2008 03:50:29 GMT


 The call to Toast.makeText() should happen on the UI thread, not on a
background thread like you are doing right now. You can use
View.post() or create a new instance of Handler and call post() on it
to executed your code on the UI thread.








-- 
Romain Guy
www.curious-creature.org

--~--~---------~--~----~------------~-------~--~----~



application freezing with Looper

by Pedro Cristov茫o » Tue, 20 May 2008 03:50:31 GMT


 thanks for your reply, romain guy.

if i don't use the Looper i get this error: "Can't create handler
inside thread that has not called Looper.prepare()."




--~--~---------~--~----~------------~-------~--~----~



application freezing with Looper

by Pedro Cristov茫o » Tue, 20 May 2008 03:53:46 GMT


 thanks for your reply, romain guy.

if i don't use the Looper i get this error: "Can't create handler
inside thread that has not called Looper.prepare()."




--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Overlay a transparent bitmap on Camera

Hello,

I'm passing a bitmap through a bundle to an activity which I called
cameraView on which the user has access to the camera of the device.
I'd like to overlay that bitmap with transparency using the camera as
the background. Is it possible? to put the bitmap in front of the
camera? And how can I change the transparency level?

Thank you very much

Here is my code:

This is the camview.xml:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">

<SurfaceView android:id="@+id/surface_camera"
android:layout_width="fill_parent" android:layout_height="10dip"
android:layout_weight="1">

</SurfaceView>

</RelativeLayout>

-----------------

And this is the java:

public class cameraView extends Activity implements
SurfaceHolder.Callback{

        SurfaceView mSurfaceView;
        SurfaceHolder mSurfaceHolder;
        Camera mCamera;
        boolean mPreviewRunning=false;
        private Context mContext = this;

        public void onCreate(Bundle icicle) {
                        super.onCreate(icicle);

                        setContentView(R.layout.camview);
                        Bundle f = getIntent().getExtras();
                        picture = f.getParcelable("bitmap");


                        mSurfaceView = (SurfaceView) 
findViewById(R.id.surface_camera);

                        mSurfaceHolder = mSurfaceView.getHolder();

                        mSurfaceHolder.addCallback(this);

                        
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

        }

        @Override
        // Create the Surface and Open the Camera
        public void surfaceCreated(SurfaceHolder holder) {
                mCamera = Camera.open();
        }

        @Override
        // Reacts for camera changes
        public void surfaceChanged(SurfaceHolder holder, int format, int
w,int h) {
                if (mPreviewRunning) {
                        mCamera.stopPreview();
                        }
                        Camera.Parameters p = mCamera.getParameters();
                        p.setPreviewSize(w, h);
                        mCamera.setParameters(p);
                        try {
                        mCamera.setPreviewDisplay(holder);
                        } catch (IOException e) {
                        e.printStackTrace();
                        }
                        mCamera.startPreview();
                        mPreviewRunning = true;
        }

        @Override
        // When the camera is closed
        public void surfaceDestroyed(SurfaceHolder holder) {
                mCamera.stopPreview();
                mPreviewRunning = false;
                mCamera.release();
        }

        // When the picure is taken. This method gives the byte[] of the
picture
        Camera.PictureCallback mPictureCallback = new
Camera.PictureCallback() {

                public void onPictureTaken(byte[] imageData, Camera c) {
                }

                };

}

-- 

2. Microsphone cannot be recorded on android emulator

Hi,


A small program that I wrote cannot record the microphone. One api
call, getminbuffersize keeps returning -2 which is not correct. The
program works on a real android one.

I use 11025Hz, 16bit pcm,mono recording..
Can you give me a suggestion what can be wrong?

Thank you.


aftershock

-- 

3. Getting the updated array of data from a ListView/Adapter

4. how to close activity from service

5. Posting Toast From Worker Thread to UI Thread

6. ListView containing multiple, clickable, Views (i.e. like GMail)

7. How to handle OutofMemoryError in a service?