Log in or register to post comments

switching activities using android and qcar

August 8, 2011 - 2:01am #23

hello, i would like to switch activities from imagetargetsrenderer.java to a custom activity class i wrote. the problem is that while switching is no problem, switching back to the tracking activity in imagetargets by pressing the back button causes my custom activity to restart. to get a better picture, here is my logcat:

08-08 14:45:54.284: WARN/System.err(5423): ImageTargetsRenderer reports: 0
08-08 14:45:54.325: WARN/System.err(5423): ImageTargetsRenderer reports: 0
08-08 14:45:54.364: WARN/System.err(5423): ImageTargetsRenderer reports: 1
08-08 14:45:54.374: WARN/System.err(5423): Starting to switch activities.
08-08 14:45:54.394: WARN/System.err(5423): ImageTargets super.onPause.
08-08 14:45:54.424: WARN/System.err(5423): ImageTargets mGlView.onPause.
08-08 14:45:54.424: WARN/System.err(5423): ImageTargets QCAR.onPause.
08-08 14:45:54.924: WARN/System.err(5423): TestActivity Reporting.
08-08 14:45:57.824: WARN/System.err(5423): ImageTargets super.onResume.
08-08 14:45:57.824: WARN/System.err(5423): ImageTargets QCAR.onResume.
08-08 14:45:58.595: WARN/System.err(5423): ImageTargets mGlView.onResume.
08-08 14:45:58.724: WARN/System.err(5423): ImageTargetsRenderer reports: 1
08-08 14:45:58.724: WARN/System.err(5423): Starting to switch activities.

here is my code:

imagetargetsrenderer.java

public void onDrawFrame(GL10 gl) {
		testFlag = 0;
		
		if (!mIsActive)
			return;

		// Call our native function to render content
		testFlag = renderFrame();
		
		System.err.println("ImageTargetsRenderer reports: " + testFlag);
		
		if(testFlag > 0)
        {
			System.err.println("Starting to switch activities.");
			Intent myIntent = new Intent(context, TestActivity.class);
			myIntent.putExtra("com.qualcomm.QCARSamples.ImageTargets.flagTest", testFlag);
			myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			context.startActivity(myIntent);
			testFlag = 0;
			return;
        }
       
		
	}

imagetargetsrenderer.java takes an int value and reports it in the logcat upon detection of a trackable. 1 if a trackable is detected and 0 vice versa. basically testactivity is called twice because on mGlView.onResume(). i'm not too sure what is happening here, partly because i don't have the code for GLViewRenderer.class.

is there a way to switch back to the tracking activity without the custom activity restarting itself before doing so?

Re: switching activities using android and qcar

August 8, 2011 - 2:49pm #22

This is probably an issue with leftover camera frames causing a false positive as soon as you return to the main activity. Try skipping the result of the first few frames, something like this:

if (testFlag > 0 && frameCount > 5)
{
    frameCount = 0;
    ...
}

frameCount++;

- Kim

Re: switching activities using android and qcar

August 10, 2011 - 7:40pm #21

thanks ksiva! it works as expected now.

Re: switching activities using android and qcar

September 16, 2011 - 5:33am #20
Quote:
public void onDrawFrame(GL10 gl) {
		testFlag = 0;
		
		if (!mIsActive)
			return;

		// Call our native function to render content
		testFlag = renderFrame();
		
		System.err.println("ImageTargetsRenderer reports: " + testFlag);
		
		if(testFlag > 0)
        {
			System.err.println("Starting to switch activities.");
			Intent myIntent = new Intent(context, TestActivity.class);
			myIntent.putExtra("com.qualcomm.QCARSamples.ImageTargets.flagTest", testFlag);
			myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			context.startActivity(myIntent);
			testFlag = 0;
			return;
        }
       
		
	}

I have a different problem when switching activities.. I have something similar to the above in my renderer. When I create my renderer I pass the ImageTargetsActivity context as an argument. When I detect a poster it triggers a flag and starts a new activity exactly as above..

In my manifest file I place for my activity android:noHistory="true"
in order the user not being able to navigate back to the camera background.

The problem is the following. When the new activity is created the onPause() method is called in ImageTargets Activity which then calls QCAR.onPause();

At that point I receive the following error:

call to OpenGL ES API with no current context ( logged once per thread)

Can anyone please help me? I realize that this is caused because a call to OpenGL is made not from the OpenGL thread but how do I fix it??

Re: switching activities using android and qcar

September 16, 2011 - 1:05pm #19

I think that error is harmless, it seems to occur when you press the back button in any sample application (even without the extra activity). Is it causing any problems?

- Kim

Re: switching activities using android and qcar

September 17, 2011 - 10:29am #18

this error is not harmless..1/6 of the times that the app runs and performs the switching of activities it stacks for about 1-2 sec to a black screen before switching the activities and the phone vibrates..In the LogCat I can see something like

Failed to write to stack traces

printed 3-4 times..The applications continues to the next activity but this behavior is not acceptable..Is there a way to fix it?

p.s thank you very much for the reply..

Re: switching activities using android and qcar

September 19, 2011 - 10:57am #17

did you pass the context from imagetargets.java into imagetargetsrenderer.java? you should pass it through a constructor in the imagetargetsrenderer java file.

i used something like:

private Context context;
public ImageTargetsRenderer(Context context) {
this.context = context;
}

you also need to modify imagetargets.java to pass the context through after instantiating mRenderer or something like that.

Re: switching activities using android and qcar

September 19, 2011 - 12:48pm #16
mslhii wrote:

did you pass the context from imagetargets.java into imagetargetsrenderer.java? you should pass it through a constructor in the imagetargetsrenderer java file.

i used something like:

private Context context;
public ImageTargetsRenderer(Context context) {
this.context = context;
}

you also need to modify imagetargets.java to pass the context through after instantiating mRenderer or something like that.

That is exactly what I did!!! I passed the context through the constructor..I don't think it concerns the context since the QCAR.onPause method that is called when switching activities seems to call OpenGL functions and thid is not done in the OpenGL thread..The problem happens within the QCAR library!!!!

Re: switching activities using android and qcar

September 19, 2011 - 6:19pm #15

I can't seem to reproduce this. I do see that error in the log, once, but the activity switches immediately and there are no other errors. Could you possibly send your project to

? You can use our file sharing service: http://me2u.qualcomm.com

It's possible this is a device-specific bug as well, what device are you testing with, and what version of Android?

- Kim

Re: switching activities using android and qcar

September 20, 2011 - 1:25am #14
ksiva wrote:

I can't seem to reproduce this. I do see that error in the log, once, but the activity switches immediately and there are no other errors. Could you possibly send your project to

? You can use our file sharing service: http://me2u.qualcomm.com

It's possible this is a device-specific bug as well, what device are you testing with, and what version of Android?

- Kim

Dear Kim, I am afraid I can not do this..

I think the problem is obvious. We are in the renderer and we are working on the OpenGL thread. When the poster triggers you switch to the Main UI Thread which handles the activity which calls onPause() before moving to the next activity..The onPause method calls QCAR.onPause() which obviously calls some OpenGL functions probably for releasing the OpenGL matrices..This call is made from the Main UI Thread and that is why the error happens..It happes 1/6 maybe..

What is the right approach to implement this triggering and how you should switch to the other activities from the renderer and not enabling navigation back?

Shall we call finish() after triggering or using noHistory in manifest file?

I am working on:

Samsung Galaxy Tab (7') : Android 2.2
Samsung Galaxy S: Android 2.3.3

Re: switching activities using android and qcar

September 20, 2011 - 10:21am #13

Bear with me here. I still think that OpenGL error is a red herring. We won't be able to give you a fix for it here anyways, it's something we'll fix in a future release.

I'm curious, do you see the same problem if you switch activities without using the "no history" flag? If not, this is probably an issue with our reporting feature. When the QCAR activity finishes it sends some anonymous usage data to our servers (see the license agreement). Typically this happens when the user puts the app to the background, so they never see a delay. But here you're finishing the QCAR activity early.

We'll have to investigate this workflow for future improvement. In the meanwhile, I would suggest leaving the AR activity on the stack and either capturing the back button event and overloading it (going to a different activity) or perhaps calling finish() on it at a different time where the delay won't cause issues.

- Kim

Re: switching activities using android and qcar

September 20, 2011 - 11:57pm #12
ksiva wrote:

Bear with me here. I still think that OpenGL error is a red herring. We won't be able to give you a fix for it here anyways, it's something we'll fix in a future release.

I'm curious, do you see the same problem if you switch activities without using the "no history" flag? If not, this is probably an issue with our reporting feature. When the QCAR activity finishes it sends some anonymous usage data to our servers (see the license agreement). Typically this happens when the user puts the app to the background, so they never see a delay. But here you're finishing the QCAR activity early.

We'll have to investigate this workflow for future improvement. In the meanwhile, I would suggest leaving the AR activity on the stack and either capturing the back button event and overloading it (going to a different activity) or perhaps calling finish() on it at a different time where the delay won't cause issues.

- Kim

Dear Kim please help me understand..If I switch activities and not call finish on the qualcomm activity only onPause() will be called if I don't use noHistory in manifest. This problem still happens. The only difference when calling finish() is that onPause() will be called and afterwards onDestroy(). The problem you are suggesting is in onPause() or in onDestroy()?? How shall I kill qualcomm activity on a later stage from the new activity??

Thanks in advance,

Andreas

Re: switching activities using android and qcar

September 21, 2011 - 12:06am #11

This is a screenshot of Logcat to show my problem. During this the screen goes black and the phone vibrates. Then it moves to the next activity.

p.s the above example did not call finish(), it just started a new activity that was placed at the top of the activity stack. Below is the code:

 protected void onPause()
    {
    	super.onPause();
		
    	Log.e("Test", "----------------------------------------  onPause()-------------------------------");

      
        if (mGlView != null)
        {
            mGlView.setVisibility(View.INVISIBLE);
            mGlView.onPause();
        }
        
    	Log.e("Test", "-----mGlView.onPause();----------");
    	
        
        // QCAR-specific pause operation
        QCAR.onPause();
        
        Log.e("Test", "-----QCAR.onPause();----------");

        
        if (mAppStatus == APPSTATUS_CAMERA_RUNNING)
        {
            updateApplicationStatus(APPSTATUS_CAMERA_STOPPED);
        }
        
        Log.e("Test", "----- updateApplicationStatus(APPSTATUS_CAMERA_STOPPED);----------");

    }

Re: switching activities using android and qcar

September 22, 2011 - 8:55pm #10

It looks like there's a crash, although it's strange that a stack trace isn't printed. We'll look into the issue as soon as possible, it seems to be device-specific.

In the meanwhile, you may want to try switching the activity from the main thread instead of the GL thread, e.g. by using a Handler. Just a thought.

- Kim

Re: switching activities using android and qcar

September 23, 2011 - 12:45am #9
ksiva wrote:

It looks like there's a crash, although it's strange that a stack trace isn't printed. We'll look into the issue as soon as possible, it seems to be device-specific.

In the meanwhile, you may want to try switching the activity from the main thread instead of the GL thread, e.g. by using a Handler. Just a thought.

- Kim

Dear Kim,

Thanks for the reply. It is not device specific. Also tested on

Samsung Galaxy Fit S5670

What I don't understand is that when I switch the activities, the onPause() will eventually be called( this is the place that that the problem occurs)..Isn't this called from the main UI anyway??

Regards,

Andreas

Re: switching activities using android and qcar

September 27, 2011 - 2:28pm #8

Unfortunately we haven't been able to reproduce this issue after testing on a number of devices. I've tried to replicate your problem with a sample app based on your description here, but without more info we won't be able to help.

Could you possibly send an APK that displays the problem, so we can determine what devices are affected? I'm also curious what your custom activity does, does it use the camera at all?

Do you see the same problem with a bare-bones custom activity? For example:

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class TestActivity extends Activity
{
    protected void onCreate(Bundle savedInstanceState)
    {
        DebugLog.LOGD("TestActivity::onCreate");
        super.onCreate(savedInstanceState);
        
        TextView tv = new TextView(this);
        tv.setText("Hello, Android");
        setContentView(tv);
    }
}

Thanks,

- Kim

Re: switching activities using android and qcar

November 12, 2011 - 3:04am #7

Hi Ksiva,

I want to switch activity after detecting trackable to a video view in ImageTargets sample code. Where should i modify the code to achieve the same. Please help me out.

Thanks
Rahul

Re: switching activities using android and qcar

November 12, 2011 - 10:28am #6

Take a look at this thread: http://ar.qualcomm.at/node/2001096

- Kim

Re: switching activities using android and qcar

November 14, 2011 - 1:46am #5

Thanks Kim, Its working!!! :-)

Re: switching activities using android and qcar

January 27, 2012 - 4:58am #4

Hi Kim, this thing is not working in 1.5 beta. What changes should i make to work it again in 1.5 ver.

Re: switching activities using android and qcar

January 29, 2012 - 9:21am #3

I just recreated the video test with the 1.5 beta and didn't run into any problems. Make sure you've updated your manifest to include the video activity.

I suggest using the new ImageTargets sample as a starting point.

What errors are you seeing in the log?

- Kim

Re: switching activities using android and qcar

January 29, 2012 - 10:37pm #2

Hi Kim,

Video activity is there in the manifest and its not showing any error. Its showing the teapot instead of starting video activity, even after making changes suggested by you.

Rahul

Re: switching activities using android and qcar

January 30, 2012 - 6:34pm #1

Make sure your Java play video method is getting called, by adding a log line or using the Eclipse debugger. Try tracing each step to make sure all the correct methods are getting called.

Did you build your native code using ndk-build and refresh the Eclipse project?

- Kim

Log in or register to post comments