Hi there,

I did not see an Android thread, but its pretty much an extension of J2SE so this is probably the best place for it..

I'm currently developing on minimum sdk version 3 (Android 1.5 - cupcake) and I'm having a strange unexplained issue that I have not been able to solve on my own. It is now becoming a rather Urgent issue as I've already missed 1 deadline...

I'm writing a high-level library to make long term android development easier and quicker. The one specific module has to capture images for a application... I've gotten everything right so far over the last couple months, except this one little thing and I don't know what to do any more:

When I use the Camera object and implement a SurfaceHolder.Callback, the methods surfaceCreated() and surfaceChanged() are called one after the other. Then when the activity finishes, surfaceDestroyed() is called. This is how it should be, but when I stick the exact same code in my library (Plain Java library that references the Android API - not in an activity), surfaceDestroyed() is called directly after created and changed.

As a result - the camera object is closed before I can use it and the application force closes. What a pain. I can't do anything! This method call is controlled by the device.. Why does the surface close for no reason? Even when I post it to run on the activity thread through my own invokeAndWait(Runnable) method, like I do for many other things.

I have 5 different working examples of different ways and implementations of capturing images in android but I still get the same issue when I plug it into my library. I don't understand what the difference is? The code is pretty much the same - and I post all the related code to the UI thread so its not a thread handling issue or anything like that. I've rewritten it about 20 times- same issue every time..

The only other way to approach it that I know of is creating a new Camera and setting it to the VideoView. The android source (c++ native code) however provides no Camera constructor, only an open() method which automatically forwards the camera's state to 'prepared' but I can only set the camera to the VideoView from the 'initialized' state. Pretty silly, I know, but there is no way around it unless I modify the Android library source code haha. not an option! The API does not allow for this method - you are expected to use it like my first example.

So essentially - i just need to understand exactly why surfaceDestroyed() is called out of turn and if there is anything I can do to avoid it closing? If i can just understand the exact logic behind it and how it works! The documentation isn't much help! Secondly, if someone knows of any alternative ways to do it, as my second example, but hopefully one which the API actually allows for?? haha

Thanks guys. I would post code, but its fairly complicated, a couple thousand lines for this specific class and it would probably take a couple days to explain with all the threading and event listeners and what not. I just need help with this 1 single thing. Please let me know if you have any questions.

Thanks again!

not urgent.

not urgent.

I don't understand why you would say that? It is rather urgent. I have just missed my second deadline for this. I would appreciate a little more than that??

Sorry I do not know anyone of this forum with sufficient knowledge to answer your question. You better try to post on some Android forum...

Sorry I do not know anyone of this forum with sufficient knowledge to answer your question. You better try to post on some Android forum...

I have posted it on the Android forums, not getting any valid answers so pretty much trying everywhere. Thanks for having a look though!

I'll probably have to get hold of one of the guys that developed Android to answer my question! haha.

too late now anyway, if it were really urgent.

too late now anyway, if it were really urgent.

Very unnecessary... This is my job on the line. 'too late now anyway' is a bit rude, don't you think?

If you don't have anything constructive to contribute, please refrain from posting anything and keeping the thread clean for someone who might actually have something of value to contribute. Thank you

Somewhere in my implementation of View management between refreshing (repaints) and menu handling the camera view got temporarily hidden, probably only for a few milliseconds. Being hidden calls surfaceDestroyed, so when it wants to display again, the surface is no longer available.

Stupid issue that was hidden quite deeply in my implementation of managing views. That would explain why it always worked with canvas' and other implementations, but only had a problem when it came to the camera's surface (only one that actually destroys the surface when hidden). took me a good week to find. anyway - problem solved now.

@Avasulthiris well done

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.