Developing a little game

I am trying to make a game.

I have a mainActivity which is called BridgeScene here and I create a class for the ennemy

In the mainActivity, I have two ImageView and some button!

In my class, I have an ennemy (represented by a Rectangle) and I use Canvas to draw a Rectangle. What I need to is to draw this Rectangle on my BridgeScene Activity. How can I do that?

I cannot set the contentview twice because it is already set in the activity as setContentView(R.layout.activity_bridge_scene);

So how can I draw my rectangle from my class ennemy in my BridgeScene activity?

My activity:

public class BridgeScene extends AppCompatActivity {
private static final  int[] ALL_DRAWABLE_RES_EAGLE = new int[]{

private Ennemy1 ennemy1;

private Handler handler = new Handler();
private final static long Interval = 30;

private Runnable updateImageTask;
private int currentDrawableResIndex;

private static long IMAGE_UPDATE_DELAY_MILLIS = 30;

private ImageView imvStickman;
private ImageView imvJump;

protected void onCreate(Bundle savedInstanceState) {

    ennemy1 = new Ennemy1(this);

    updateImageTask = new UpdateImageTask();

    imvJump = (ImageView) findViewById(;

    imvStickman = (ImageView) findViewById(;
    imvEnnemi = (ImageView) findViewById(;

    imvJump.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {


My class:

public class Ennemy1 extends View{
public Bitmap rec;
public int recX;
public int recY;

public int canvasWidth;
public int canvasHeight;

public Ennemy1(Context context){
    rec = BitmapFactory.decodeResource(getResources(), R.drawable.enem1);

protected void onDraw(Canvas canvas) {
    canvas.drawBitmap(rec, 100, 100, null);
    canvasWidth = canvas.getWidth();
    canvasHeight = canvas.getHeight();


#java #android

1.35 GEEK