opengl es - Android activity life cycle - restarting (destroying) app does not remove reference to (custom) listener? -


i have application using glsurfaceview , renderer. have set when user exits application via button call myactivity.finish();

this fine , can see activity getting calls onstop() , ondestroy();

the app works fine first time run when subsequently run have had problem motionevents.

i handle motion events queuing them pool , having renderer access pool @ right time so:

try     {         //get history first         int hist = event.gethistorysize();         if (hist > 0)         {             //oldest first in list. (i think).             (int i=0;i <hist; i++)             {                 inputobject input = inputobjectpool.take();                 input.useeventhistory(event, i);                 defrenderer.feedinput(input);             }         }          //the current 1 still needs added         inputobject input = inputobjectpool.take();         input.usemotionevent(event);         defrenderer.feedinput(input);     } 

and in renderer:

            synchronized (inputqueuemutex)      {         arrayblockingqueue<inputobject> inputqueue = this.inputqueue;         while (!inputqueue.isempty()){try             {                 inputobject input = inputqueue.take();                  if (input.eventtype == inputobject.event_type_touch)                 {                     screenmanager.processmotionevent(input);                  }                 else if (input.eventtype == inputobject.event_type_key)                 {                     screenmanager.processkeypress(input);                 }                  input.returntopool();             }             catch (interruptedexception ie)             {                 dlog.deferror("interrupted blocking on input queue.", ie);             }         }     } 

as can see in above code hand these motion events screenmanager way of having several "scenes" render out. works fine first time run application , screen interprets motion touches movement of simple square @ moment.

however second time run application square drawn screen fine motion events nothing.

i have followed motion events , although given "new" renderer seems giving motion events old screen. or rather old object on screen. confusing in code in oncreate() method this:

//set renderer , give surfaceview     defrenderer = new defrenderer();     defview = new defview(this);     defview.setrenderer(defrenderer);      //set out content surface view.     setcontentview(defview);      //set input queue     createinputobjectpool(); 

oncreate called both first time , second time app run (and app destroyed!) screens made new in defrenderer , given new defview.

i confused how data remain in defrenderer receive motionevents app remade.

is there obvious going on missing here? have thought when ondestroy called app dereferenced , no trace of remain. not true? somehow when call new renderer(); referencing old one?

i @ loss going on really. app basic copy of have written works fine!

edit:

after small amount of experimentation have discovered motion events going old scrollpanel (an object made..) registered listener (and listener mean own implementation ..) motionevents. have made own event system these so:

public interface touchsource  public static final int type_touchdown = 0; public static final int type_touchdrag = 1; public static final int type_touchclick = 2;  public vector<touchlistener> listeners = new vector<touchlistener>();  public void addtouchlistener(touchlistener listener); public void removetouchlistener(touchlistener listener);  public void touchoccured(int type, int xpos, int ypos); 

}

and listener interface:

public interface touchlistener  public boolean touchdownoccured(int xpos, int ypos); public boolean touchdragoccured(int xpos, int ypos); public boolean touchclickoccured(int xpos, int ypos); 

so screen implements touchsource , has list of listeners. despite being remade screen currentscreen = new screen(); called in oncreate(); of manager list of listeners still populated old scrollpanel?

how this? i'm missing obvious. somehow list of listeners static reason , not getting dereferenced despite app being remade?

i suspect issue you're facing might have fact original motionevents recycled (returned pool) framework after onmotionevent() returns.

from way you're using inputobjects, think might keeping reference original motionevents in there, , not copying event data.

quickly try using motionevent.obtain(event) whereever use event (this makes copy) , see if makes weird behaviour go away. naturally, if works have recycle() copies after you're done them. not call recycle() on original motionevents though.

cheers, aert.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -