android - multiple intent's starting by onTouch event -


hey guys getting start intent if user clicks on specific location.at first touch opens menu , on second opens activity.the problem many copy's of same intent started

 import android.app.activity;  import android.content.context;  import android.content.intent;  import android.graphics.bitmap;  import android.graphics.bitmapfactory;   import android.graphics.canvas;  import android.graphics.color;  import android.graphics.paint;  import android.graphics.paint.align;  import android.os.bundle; import android.text.textpaint; import android.view.motionevent;  import android.view.view;  import android.view.view.ontouchlistener;  import android.widget.toast;    public class gfx extends activity implements ontouchlistener{ bitmap a,b; gfx1 drw; string a1; boolean flag=false,flag1=false,flag2=false; canvas c1; float x=0,y=0,z=0,bitx=0,bity=0; protected void oncreate(bundle savedinstancestate) {     // todo auto-generated method stub     super.oncreate(savedinstancestate);     drw = new gfx1(this);     drw.setontouchlistener(this);     setcontentview(drw); }  public class gfx1 extends view implements runnable {      public gfx1(context context) {         super(context);         // todo auto-generated constructor stub         = bitmapfactory.decoderesource(getresources(),                 r.drawable.greenball);      }     void callin(string a1)     {         intent inte = new intent(a1);         startactivity(inte);     }      @override     protected void ondraw(canvas c1) {         // todo auto-generated method stub         super.ondraw(c1);         c1.drawcolor(color.yellow);         b=bitmap.createscaledbitmap(a,c1.getwidth()/3, c1.getheight()/3, true);         bitx=(c1.getwidth()/2)-(a.getwidth()/2);         bity=(c1.getheight()/2)-(a.getheight()/2);         c1.drawbitmap(a,  bitx, bity, null);          paint textpaint = new paint();         textpaint.setargb(50, 254, 10, 50);         textpaint.settextalign(align.center);         textpaint.settextsize(30);         if(flag)         {             c1.drawtext("clicked",300, 300,textpaint);             c1.drawbitmap(b,(c1.getwidth()/2)-(b.getwidth()/2),(c1.getheight()/2)+(a.getheight()/2), null);             c1.drawbitmap(b,(c1.getwidth()/2)-(b.getwidth()/2),(c1.getheight()/2)-(a.getheight()/2)-(b.getheight()), null);         }         float bitbx1=(c1.getwidth()/2)-(b.getwidth()/2);         float bitbx2=(c1.getwidth()/2)+(b.getwidth()/2);         float bitby1=(c1.getheight()/2)-(b.getheight())-(a.getheight()/2);         float bitby2=((c1.getheight()/2)-(a.getheight()/2));         if(flag2)         {             c1.drawtext("opening...please wait", 600, 600, textpaint);             flag1=true;             if(flag1)             {                 a1="com.example.claci.mainactivity";             callin(a1);             }             flag1=false;         }          if((x>bitx&&x<bitx+(a.getwidth()))&& (y>bity&&y<bity+(a.getheight())))         {             flag=true;          }         if((x>bitbx1&&x<bitbx2)&&(y>bitby1&&y<bitby2))         {     if(flag)     {                 flag2=true;     }         }         invalidate();      }      @override     public void run() {         // todo auto-generated method stub      }  }  @override public boolean ontouch(view v, motionevent event) {     // todo auto-generated method stub       switch(event.getaction()){     case motionevent.action_down:         x=event.getx();         y=event.gety();         break; }     return true; 

} }

a better structure have menu creation, , subsequent activity creation called ontouch method. psink mentioned, not proper use of ondraw, , unnecessarily links tow unrelated things.

i use 2 class variables-- 1 flag if menu exists yet, , reference newly created activity. if activity exists, don't create one. when existent activity completes, though, needs return result activity can clear reference , ready create new 1 when needed.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -