lag - Android Development: App is lagging when ontouch listener is inactive -


i haven't been able find question online similar this, thought submit question. in cases seems people have opposite problem lag may occurring during touch event, seeing exact opposite. creating air hockey game , each frame pieces moved based on current parameters, , game redrawn while in background override ontouch listener looking motion events. thing there noticeable lag when there no fingers touching screen , watching animated pieces, long there form of motion event happening, if ontouch being called, animation smooth. can not figure why is, best educated guess interrupt checking if ontouch should called consuming more resources should, know nothing how modify or check ontouch interrupt behavior @ might know.

a little more background on how organized. overall class located in main.java, created here , requests context view, game class extension of imageview. game class has @override ontouchevent, has defintions depending on state , motion event. class has draw method, , @ end of method calls h.postdelayed(r, frame_rate); r runnable @override public void run() calls invalidate();. h handler initialized in class. each time game drawn invalidate called after frame_rate elapse time of 10ms, tells game redraw. move functions game called draw method. ontouch happening along side process why smoother if on ontouch being called rather checking if true, seems counter intuitive i'm sure there logical reason. lastly lag time measurable using system clock , time dependent based on called. showed increase in passing time between games move function when touch event not occurring.

sorry long response without actual code context, hope descriptive enough. code self rather long didn't think post that, if needed can better @ re posting pseudo code visualized hierarchy. thank , suggestions problem. great able understand why happening.

here code, trying fit comment didn't realize had post editing original post.

public class main extends activity {  game game; private menus menus; // contains menu info int menu; //keep track of menu @  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);      game = new game(this);     setcontentview(game);    } @override public void ondestroy() {     super.ondestroy(); }  @override protected void onactivityresult(int requestcode, int resultcode, intent data) {  super.onactivityresult(requestcode, resultcode, data);      ..some code here process photo files }  //get orientation of loaded pictures public static int getorientation(context context, uri photouri) {     /* it's on external media. */     cursor cursor = context.getcontentresolver().query(photouri,             new string[] { mediastore.images.imagecolumns.orientation }, null, null, null);      if (cursor.getcount() != 1) {         return -1;     }      cursor.movetofirst();     return cursor.getint(0); }     public void keyboard() {     use keyboard listener , perform actions if... }  public class game extends imageview{              private game game;              //touch events             boolean pressed;              private context mcontext;             private handler h;             private final int frame_rate = 10;               boolean initdimension = false;              //constant defining time duration between click can considered double-tap             static final int max_duration = 500;              bitmap background;              int height;             int width;       public game(context context)  {                     super(context);                           mcontext = context;                      h = new handler();                      //modeinit(); // load puck game mode                     menu = 0; //after tap ontouch changes menu = 1 game           }               private runnable r = new runnable() {                      @override                      public void run() {                              invalidate();                      }              };               @override              public boolean ontouchevent(motionevent e)              {                   switch statement...                  check motion event type                     check menu state.. perform action                 }               public void modeinit()              {                    game = new game( mcontext, width, height );                 }               protected void ondraw(canvas c)               {                   if(!initdimension)                  {                      width = this.getwidth();                      height = this.getheight();                      initdimension = true;                  }                  else                  {                       //logo screen                      if(menu == 0)                      {                            menu = menus.displayintro(c);                      }                     //game mode                      else if(menu == 1)                      {                            game.paint_game(c);                            long run_test = system.nanotime()/1000;                             game.move();                            log.d("run time: ",": "+(system.nanotime()/1000-run_test)); //ontouch lag test                      }                      ... other menu items here                  }                  h.postdelayed(r, frame_rate);            }      }    } 


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -