After this application closes immediately. Everything works fine if the POIs finish loading by the time we decide to switch from the view however.
This happens on all of the devices we use for testing including Milestone with Froyo and Nexus S with JB. We are using Wikitude SDK 1.1.
This doesn't seem to reproduce with Wikitude application itself, probably because ArchitectView has its own activity there. In our case we're using a number of views (one of which is AR view) in the same activity. By "switching from" I mean calling onPause and onDestroy for AR view and setting the content view to another view.
Is there a way to switch between AR view and other view in the same activity without having to destroy and recreate the AR view every time btw? I've tried some but none of it worked.
A
Andreas Fötschl
said
about 11 years ago
Hi there!
Please use Fragments to switch between views in same Activity. They are supported for SDK 11+. I recommend you to use the custom compatibility pack which allows you to use MapViews inside Fragments too. You can then use transactions to change views on the fly. Since MapView and Cam consume quite a lot memory I recommend you not to have both views/fragments in memory but restore fragment instead.
Find more details about the compatibility pack at Android Developer Website. Yepp, it's a bit more to read through, but you then know you are using latest technology and can even use latest titlebar across all version using the ActionBar.
Hope that helps. Kind regards, Andi
Y
Yegor Vedernikov
said
about 11 years ago
Hi Andreas,
Thanks for the hint. We'll try that out and get back to you with the results.
Y
Yegor Vedernikov
said
about 11 years ago
Hi again,
I'm trying out the Fragments with our app atm. It looks like the seg fault doesn't happen with them but I can't switch to AR view now (switching from it and between other views works fine). I'm using the dynamic fragments.
If I start with, say, list view and then replace it with the AR view I get this:
10-25 14:47:57.942: E/AndroidRuntime(5179): java.lang.RuntimeException: Failed to initialise PVRShell
10-25 14:47:57.942: E/AndroidRuntime(5179): at com.wikitude.architect.PVRShell.initialise(Unknown Source)
10-25 14:47:57.942: E/AndroidRuntime(5179): at com.wikitude.architect.PVRShellView$OurContextFactory.createContext(Unknown Source)
10-25 14:47:57.942: E/AndroidRuntime(5179): at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:922)
10-25 14:47:57.942: E/AndroidRuntime(5179): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1246)
10-25 14:47:57.942: E/AndroidRuntime(5179): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)
I get the same if I start with AR view, then switch to list, then to AR again having ArchitectView.onDestroy() call in onDestroy() fragment method.
If I comment it out I get an empty cam view in the end of this scenario (I expect to see at least a radar). This basically looks the same to problems I had with switching to AR view using setContentView() before coming up with a solution to always destroy it when switching from and recreate from scratch when switching to it.
So the question is... what am I doing wrong? :)
It would be nice to have a snippet for AR view with switching fragments.
Y
Yegor Vedernikov
said
about 11 years ago
Ok, I've made some progress here actually. I can switch from/to AR view using the Fragments API now... well, with some strings attached.
I had to make the following changes to achieve the desired behavior:
* Inflate AR layout only the first time and return the cached AR view on the subsequent calls to the onCreateView
* Remove AR view from it's parent view in onDetach
* don't destroy AR view in fragment onDestroy(), add a specific method that is called when activity gets destoyed
* move the AR onPostCreate and load the world code to happen right after AR onCreate in onCreateView (this way I can start with another view and then switch to AR as well as start with AR view and switch to another one)
However, this only works currently for Nexus S with JB 4.1.2 or Galaxy Nexus with JB 4.1.1 and doesn't for Milestone with Froyo 2.2.1 or i9000 with Gingerbread 2.3.5. So I suspect that it only works for android-11+ devices (there is a delay begore radar and the objects get visible however). On the older devices I get an empty cam view after switching back to AR view and it never updates even after I see my app communicates (calls the js method) with AR in logs.
I can also reproduce the seg fault using the Fragments API on JB Nexus S if I put the AR onDestroy call in fragment onDetach method and try to replace the AR view while it's still loading the objects.
Now to the funny part - I've reverted to use the setContentView instead of fragment transactions and managed to get rid of seg fault by cutting out the AR onDestroy during switching from it (I still call it when the app is destroyed) and use the cached AR view in setContentView. This works fine on JB Nexus S and JB Galaxy Nexus but I still get an empty cam view after going back to AR on older devices. So it looks like this behavior is the same regardless of using fragments and the real issue is that AR onDestroy should not be called while removing it from scene while some activity is happening there.
And I'm a bit stuck here :(
I have a version that is working across all devices but has a seg fault and I have a seg fault free version which doesn't work on older devices.
Please advice.
M
Markus Eder
said
about 11 years ago
Hello!
Can you tell me more about your project setup, especially are you using a ViewPager to switch between your fragments? If that's the case you could prevent that the ArchitectView is destroyed when you switch between Fragments, by overriding the destroyItem-method of the FragmentPagerAdapter class, as can be seen in this example:
I'm not using the ViewPager, should I? Also, I've already mentioned above that I can overcome the seg fault issue with onDestroy but then the solution doesn't work with 2.2, 2.3 devices (empty cam view).
General project setup is as follows:
- min sdk is android-8
- main activity with 3 switching views/fragments (AR, list, map) which are updated with live data
- data service class (not a service) fetching data in a background thread
- other minor activities launched from the main one
Application tracks the current location and provides a feedback in form of relevant POIs displayed in form of AR markers / List entries / Map pushpins).
Relevant code for AR view (for the version using fragments):
// onCreate method for setting the license key for the SDK
if (_architectView != null)
_architectView.onCreate(LICENSE_KEY);
doPostCreate();
return view;
}
@Override
public void onPostCreate()
{
_logger.debug("onPostCreate");
// doPostCreate();
}
private void doPostCreate()
{
_logger.debug("doPostCreate");
if (_architectView == null)
return;
// IMPORTANT: creates ARchitect core modules
_architectView.onPostCreate();
// register as handler of "architectsdk://" urls
_architectView.registerUrlListener(this);
try
{
_architectView.load("world.html");
}
catch (final IOException e)
{
_logger.error("failed to load AR world", e);
}
}
@Override
public void onLowMemory()
{
if (_architectView != null)
_architectView.onLowMemory();
}
@Override
public void onPause()
{
_logger.debug("onPause");
super.onPause();
if (_architectView != null)
_architectView.onPause();
}
@Override
public void onResume()
{
_logger.debug("onResume");
super.onResume();
if (_architectView != null)
_architectView.onResume();
}
@Override
public void onDestroy()
{
_logger.debug("onDestroy");
super.onDestroy();
// if (_architectView != null)
// _architectView.onDestroy();
}
@Override
public void onDestroyActivity()
{
super.onDestroyActivity();
if (_architectView != null)
_architectView.onDestroy();
}
...
}
M
Markus Eder
said
about 11 years ago
Hello!
We've tested the usage of the ArchitectView in Fragments mostly using ViewPager and FragmentPagerAadapter, so maybe you wanna try out that way as well. The problem on 2.2 and 2.3 devices you mentioned is related to the Android Webkit implemententation on those devices. The ArchitectView is currently optimized for usage in activities and therefore this problem doesn't exist in those scenarios. We are working on a solution for that problem for your scenario and will include it in the upcoming release of our SDK.
Hope that helps,
Markus
Y
Yegor Vedernikov
said
about 11 years ago
Hello Markus,
Unfortunately ViewPager didn't work out for us. We have a requirement to have 2 map views available in application and it's not possible with ViewPager concept. Also it only works for old devices if we use FragmentStatePagerAdapter with destroyItem() overriden to skip destroying the item which probably keeps all the views in memory and Andreas already mentioned this as a bad practice.
We have switched to use the separate activities for our views and the problem doesn't seem to reproduce any more.
Yegor Vedernikov