www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: dajack05 on December 20, 2011, 04:06:52 am

Title: Start jpct-ae fresh when activity starts.
Post by: dajack05 on December 20, 2011, 04:06:52 am
Here is my issue... I am launching an activity which holds all the jpct-ae stuff. But I want to be able to quit that activity and then start it again later but it needs to start fresh (Like from onCreate).

I have tried calling finish() at onPause() and I have noHistory set as True but it always wants to resume from where it was before.

Any advice?

Thx in advanced,
Daniel
Title: Re: Start jpct-ae fresh when activity starts.
Post by: EgonOlsen on December 20, 2011, 06:49:01 am
There might be a cleaner solution, but if i want this behaviour, i usually do a System.exit(0); in all these doPause()/doStop()/...-methods(). That terminates the VM and frees all resources.
Title: Re: Start jpct-ae fresh when activity starts.
Post by: redfalcon on December 20, 2011, 10:14:08 am
Where do you initialize the jpct-stuff? You likely want to put it into a method and call it in onCreate() and onResume().
Title: Re: Start jpct-ae fresh when activity starts.
Post by: EgonOlsen on December 20, 2011, 10:33:52 am
In onCreate()...as you can see in the examples. But i don't claim that that's the best way. My understanding of Android's lifecycle management is limited... ;)
Title: Re: Start jpct-ae fresh when activity starts.
Post by: redfalcon on December 20, 2011, 10:39:28 am
I was asking the thread author ;)

Usually, onCreate is only called if the activity is, well, created. If you switch to another activity, the current one is paused. If you switch back to the paused activity onResume() is called. But since on switching activites the OpenGL context may get destoyed and you need to re-initialize your 3D-stuff. Depending on where you do that, onResume() or onSurfaceChanged() is a good place to do so.
Title: Re: Start jpct-ae fresh when activity starts.
Post by: dajack05 on December 21, 2011, 07:53:02 pm
I am loading everything in "if (master == null)" under "public void onSurfaceChanged(GL10 gl, int w, int h)"

So I should put all my code for loading in another function and then call that at onCreate()?
Title: Re: Start jpct-ae fresh when activity starts.
Post by: dajack05 on December 21, 2011, 08:28:49 pm
I GOT IT! lol
I just needed to set master to null and flush the textures and now it works perfectly.

Thanks for your help guys :)