"We offer new support options and therefor the forums are now in read-only mode! Please check out our Support Center for more information." - Vuforia Engine Team

UNITY TO ANDROID - QCAR Has Already Been Initialized

Hi,

 

I would like to know how to solve this issue of 'QCAR has already been initialized'.

 

Let's say I want to create Android application that uses QCAR/Vuforia that is done in Unity.

The app must be able to traverse between activities including those activities that are used for Vuforia.

 

Let's call the Activity with QCAR, QCARActivity.java

I know that QCAR can only be initialized once, so when we access QCARActivity.java once, it will be able to load the activity correctly.

Below is the piece of code for QCARActivity:

public class QCARActivity extends NativeActivity {
	protected UnityPlayer mUnityPlayer;
    protected QCARPlayerSharedActivity mQCARShared;        

	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);

		getWindow().takeSurface(null);
		setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
		getWindow().setFormat(PixelFormat.RGB_565);

		mUnityPlayer = new UnityPlayer(this);

		if (mUnityPlayer.getSettings().getBoolean("hide_status_bar", true))
			getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
					WindowManager.LayoutParams.FLAG_FULLSCREEN);

		final int glesMode = mUnityPlayer.getSettings().getInt("gles_mode", 1);
		final boolean trueColor8888 = false;

		mQCARShared = new QCARPlayerSharedActivity();
		mQCARShared.onCreate(this, glesMode,
				new QCARPlayerSharedActivity.IUnityInitializer() {

					@Override
					public void InitializeUnity() {
						mUnityPlayer.init(glesMode, trueColor8888);
						View playerView = mUnityPlayer.getView();
						setContentView(playerView);
						playerView.requestFocus();
					}
				});

	}

      //Other methods such as onDestroy, onPause, onResume will also be implemented
}

 

but when we call this activity the 2nd time, it cannot load and will display 'QCAR has already been initialized' in the Logcat.

Is there anyway that we can do to mark that QCAR has already been initialized?

Then if it is already been initialized, how to open the UnityPlayer again so that it wont initialised the QCAR and displays it correctly?

 

I hope someone can enlighten me on this. Code sample will be appreciated much.

Thank you so much.

 

NOTE: So far I only know how to create Vuforia application through Unity, I used export as Google Project method to extract it to Eclipse compatible java project. I am still not familiar with programming Vuforia directly with Android.