title: Finish game loop and go to another activity Android 2.1
body: <p>Please help me answer this challenge. I have been looking all over the internet and this board for the answer. I cant referr to anything that has been posted before anywhere on the internet. This question might be trivial to someone who knows whats he's doing in Android. </p>
  
  <p>Basically what im trying to do is finish the game loop and go to a results page. When the game hits the if() for the end game. The animation stops but the intent is still on top of the screen.</p>
  
  <p>How i create the intent:</p>
  
  <pre><code>package com.droidnova.android.tutorial2d;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.Window;
  import android.widget.Button;
  
  public class Menu extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.menu);
      Button btnStart = (Button) findViewById(R.id.btnStart);
  
   btnStart.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
          Intent intent = new Intent(getApplicationContext(),Tutorial2D.class);
          startActivity(intent);
          finish();
          }});
  
  
  }
  }
  </code></pre>
  
  <p>How i create the panel:</p>
  
  <pre><code>package com.droidnova.android.tutorial2d;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.Window;
  import android.widget.Button;
  import android.view.SurfaceHolder;
  public class Tutorial2D extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      setContentView(new Panel(this));
  }
  @Override
  protected
   void onStop(){
      //finish();
      setContentView(R.layout.wynik);
      Intent intent = new Intent(getApplicationContext(),Wynik.class);
      startActivity(intent);
      //getParent();
      super.onStop();
  }
  protected void onPause(){
  finish();
  getParent();
  super.onPause();
  }}
  </code></pre>
  
  <p>Panel:</p>
  
  <pre><code>package com.droidnova.android.tutorial2d;
  
  import java.util.*;
  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.view.MotionEvent;
  import android.view.SurfaceHolder;
  import android.view.SurfaceView;
  
  
  public class Panel extends SurfaceView implements SurfaceHolder.Callback {
  
  public static float mWidth;
  public static float mHeight;
  boolean koniec=false;
  
  public float ostatnix;
  public float ostatniy;
  public int testx,testy;
  public static int c=1;
  public int punkty;
  
  public ViewThread mThread;
  private ArrayList&lt;Element&gt; mElements = new ArrayList&lt;Element&gt;();
  private int mElementNumber = 0;
  private Bitmap tlo;
  
  private Paint mPaint = new Paint();
  
  public Panel(Context context) {
      super(context);
      getHolder().addCallback(this);
      mThread = new ViewThread(this);
      mPaint.setColor(Color.WHITE);
      tlo = BitmapFactory.decodeResource(getResources(), R.drawable.tlo);
  }
  
  public void doDraw(long elapsed, Canvas canvas) {//rysujemy!!
      if(!koniec){
  
      canvas.drawBitmap(tlo, 0, 0, null);
      synchronized (mElements) {
          for (Element element : mElements) {
              element.doDraw(canvas);
          }
          }
      }
      else{canvas.drawColor(Color.BLACK);
      //canvas.draw
      };   
  
      }
  //   Element znajdz = mElements.get(0);
  //    canvas.drawText("FPS: " + Math.round(1000f / elapsed) + " Elements: " + mElementNumber +"X:  "+znajdz.x1+"Y:   "+znajdz.y1, 10, 10, mPaint);
  //    canvas.drawText("Ostatni X:  "+ostatnix+"  Y:   "+ostatniy+" testx: "+testx+" testy: "+testy+" Punkty: "+punkty, 20, 20, mPaint);
  //  }
  
  @Override
  public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
      mWidth = width;
      mHeight = height;
  }
  
  @Override
  public void surfaceCreated(SurfaceHolder holder) {
      if (!mThread.isAlive()) {
          //c=0;
          mThread = new ViewThread(this);
          mThread.setRunning(true);
          mThread.start();
      }
  }
  
  @Override
  public void surfaceDestroyed(SurfaceHolder holder) {
      if (mThread.isAlive()) {
  
          mThread.setRunning(false);
  
      }
  }
  
  public void addelements(){
      int i;
      for(i=0;i&lt;1;i++){
          mElements.add(new Element(getResources(), (int) 100, (int) 100));
          mElementNumber = mElements.size();
      }
  }
  public void koniec(){
      int i;
      for(i=0;i&lt;mElements.size();i++){
          Element znajdz = mElements.get(i);
  if(znajdz.y1&gt;mHeight*0.9){
  koniec=true;
  </code></pre>
  
  <p>Here i need to put some code that will go to results screen when this if() is true.
      }</p>
  
  <pre><code>    }
  }    
  @Override
  public boolean onTouchEvent(MotionEvent event) {
      synchronized (mElements) {  
   //       mElements.add(new Element(getResources(), (int) event.getX(), (int) event.getY()));
     //     mElementNumber = mElements.size();
  ostatnix=(float) event.getX();
  ostatniy=(float) event.getY();
  
  int b;
  for(b=0;b&lt;mElements.size();b++){
          Element znajdz = mElements.get(b);
          testx=(int) znajdz.x1;testy=(int) znajdz.y1;
          if(znajdz.x1+5&lt;event.getX()&amp;&amp;event.getX()&lt;znajdz.x1+64&amp;&amp;
                  znajdz.y1+5&lt;event.getY()&amp;&amp;event.getY()&lt;znajdz.y1+66 
                  ){
              punkty++;
              mElements.remove(znajdz);
          }
  };
  (mElements.to(array));
              //array = list.toArray(EMPTY_STRING_ARRAY);
              mElements.trimToSize(); 
              mElementNumber = mElements.size();
              if(mElements.size()==0){        int i;
                  for(i=0;i&lt;c;i++){
                  mElements.add(new Element(getResources(), (int) i, (int) i));
                  mElementNumber = mElements.size();
                  }
              c++;    
              }
      };
  
      }
      return super.onTouchEvent(event);
  }
  
  public void animate(long elapsedTime) {
      synchronized (mElements) {
          for (Element element : mElements) {
              element.animate(elapsedTime);
          }
      }
  }
  }
  </code></pre>
  
  <p>I didn't want to ask here but im forced by my lack of knowledge on the topic and unability to find the answer :( Please help.</p>