Log in or register to post comments

onChangeConfig issue

April 5, 2012 - 12:58pm #1


I have taken the ImageTargets example and am trying to make the DataSet and Trackables it uses be passed in from the Java code. This is having a side effect on initialisation process. The water is a little too deep for me, so any help would be much appreciated.

    /** Native function to initialize the application. */
    private native void setDataSet(String dataSetPath);
    /** Initializes data for tracking */
    private void initTrackingData() {
    	String path = getResources().getString(R.string.dataSetPath);

The JNI method simply sets the value of class variable
char* dataSetPath = "";

This is the point at which I make the call (first two lines)

    //Initialize data required for tracking
    // Load the tracking data set
    // This task instance must be created and invoked on the UI
    // thread and it can be executed only once!
        mLoadTrackerTask = new LoadTrackerTask();

Here's the error I receive:

04-05 20:21:33.987: D/QCAR(2792): ImageTargets::onConfigurationChanged
04-05 20:21:33.987: I/IMAGE_TARGETS(2792): Java_com_westminster_qualcomm_QCARSamples_ImageTargets_ImageTargets_setProjectionMatrix
04-05 20:21:33.987: E/AR(2792): CameraDevice::getCameraCalibration(): Failed to get camera calibration because the camera is not initialized.

It looks to me like the reason is that, under normal circumstances, "setProjectionMatrix" method is called at the end of all the intialisation at:

    // Call the native function to start the camera
    throw new RuntimeException("Invalid application state");

but for some reason my changes are making the "onConfigurationChanged()" method to be triggered, which calls the "setProjectionMatrix" earlier than it otherwise would have:

public void onConfigurationChanged(Configuration config)
        // Set projection matrix:
        if (QCAR.isInitialized())

Assuming my analysis is correct, I have two problems:
a) I don't understand what triggers onConfigurationChanged(). Is it modification of variables in native code?
b) The if statement safeguard is wrong with the changed code, but I don't know how to test for appropriate state. I can't even see "isInitialized()" in the QCAR.h

I suppose I could test for APPSTATUS_CAMERA_RUNNING, but not certain that is correct.

Re: onChangeConfig issue

April 5, 2012 - 4:28pm #2

I would call your initTrackingData() in the LoadTrackerTask, just before the call to loadTrackerData(). Does that help at all?

onConfigurationChanged is called by Android, see the documentation here: http://developer.android.com/reference/android/app/Activity.html#onConfigurationChanged(android.content.res.Configuration)

- Kim

Log in or register to post comments