-3

here is the code of the class which i created which extends MainActivity and how can i call this from MainActivity? I'm trying to figure out where I went wrong on referencing my surface view class, not my view. I only did the view as an example. Here is my main class:

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnTouchListener;

 public class SurfaceViewExample extends Activity implements OnTouchListener{

     OurView v;
     Bitmap ball;
     float x,y;

    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        v=new OurView(this);
        v.setOnTouchListener(this);
      ball=BitmapFactory.decodeResource(getResources(),R.drawable.tennis_ball);
        x = y = 0;
        setContentView(v);
    }

    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        v.resume();
    }
    public class OurView extends SurfaceView implements Runnable{
      Thread t;

      SurfaceHolder holder;

      boolean isItOk=false;

  public OurView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        holder=getHolder();
    }


    public void run() {

        // TODO Auto-generated method stub

        while( isItOk ==true)
        {
         //drawing   
         if(holder.getSurface().isValid()) {

            continue;

         }

     Canvas c=holder.lockCanvas();
         c.drawARGB(255,150,150,10);    
         c.drawBitmap(ball, x+(ball.getWidth()/4), y+(ball.getHeight()), null);

         holder.unlockCanvasAndPost(c);     

        }
     }
    public void pause()
    {
        isItOk=false;
        while(true) {
            try {
                t.join();
            }catch(InterruptedException e) {

                e.printStackTrace();

            }
            break;

        }
    }

    public void resume()
    {
       isItOk=true;  
       t=new Thread(this);
       t.start();
    }

     }
     public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub
    return false;
      } 




  } 
Madhukeshwara
  • 19
  • 2
  • 6
  • What happens when you issue an use an `Intent` for it? – sastraxi Mar 25 '12 at 06:10
  • 1
    `Intent`s are how you navigate between `Activity`s in android. Read and try to understand http://developer.android.com/guide/topics/intents/intents-filters.html. If you get stuck, ask a new question on here with the specific problem you're having! – sastraxi Mar 25 '12 at 06:19
  • here is my main activity which have reference to another class...And my question s how to run this surfaceViewExample...Main Activity is -> import android.app.Activity; import android.os.Bundle; public class Madhu1Activity extends Activity { /** Called when the activity is first created. */ Drwwingtheball v; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); v = new Drawingtheball(this); setContentView(v); } } – Madhukeshwara Mar 25 '12 at 06:42
  • Here's an example of how to start one Activity from another: http://stackoverflow.com/questions/736571/using-intent-in-an-android-application-to-show-another-activity – sastraxi Mar 25 '12 at 06:45

1 Answers1

0

The much i got is that you want to go SurfaceViewExample from your main activity for that you need to use intent on button click like

Intent i = new Intent(this, SurfaceViewExample.class);

startActivity(i) ;

and you have to add a permission in menifest to got to that activity like

<activity android:enabled="true" android:name="SurfaceViewExample" />




and you can see these links also

Calling one Activity from another in Android

http://developer.android.com/reference/android/content/Intent.html

Community
  • 1
  • 1
Avi Kumar
  • 4,403
  • 8
  • 36
  • 67