Author Topic: Start jpct-ae fresh when activity starts.  (Read 3829 times)

Offline dajack05

  • byte
  • *
  • Posts: 3
    • View Profile
Start jpct-ae fresh when activity starts.
« 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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Start jpct-ae fresh when activity starts.
« Reply #1 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.

Offline redfalcon

  • byte
  • *
  • Posts: 14
    • View Profile
Re: Start jpct-ae fresh when activity starts.
« Reply #2 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().

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Start jpct-ae fresh when activity starts.
« Reply #3 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... ;)

Offline redfalcon

  • byte
  • *
  • Posts: 14
    • View Profile
Re: Start jpct-ae fresh when activity starts.
« Reply #4 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.

Offline dajack05

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Start jpct-ae fresh when activity starts.
« Reply #5 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()?

Offline dajack05

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Start jpct-ae fresh when activity starts.
« Reply #6 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 :)