Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7684249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:58:59+00:00 2026-05-31T18:58:59+00:00

I want to pass some values from my Game extends Activity to Screen extends

  • 0

I want to pass some values from my Game extends Activity to Screen extends SurfaceView using getters, but I always got 0 and I don’t know what’s happening.

This is my code for Game class:

public class Game extends Activity{

Screen screen;
Map map;
int mouseEvent;
private int mouseX;
private int mouseY;
private Bundle extra;
private int tileRows;
private int tileColumns;
private int minBlocks;
private int maxBlocks;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    extra = getIntent().getExtras();
    tileRows = extra.getInt("numRow");
    tileColumns = extra.getInt("numColumn");
    minBlocks = extra.getInt("numMinBlock");
    maxBlocks = extra.getInt("numMaxBlock");
    setContentView(R.layout.game);
}

public boolean onTouchEvent(MotionEvent event){
    mouseEvent = event.getAction();
    mouseX = (int) event.getX();
    mouseY = (int) event.getY();
    return super.onTouchEvent(event);
}

public int getMouseX() {
    return mouseX;
}

public int getMouseY() {
    return mouseY;
}

public int getTileRows() {
    return tileRows;
}

public int getTileColumns() {
    return tileColumns;
}

public int getMinBlocks() {
    return minBlocks;
}

public int getMaxBlocks() {
    return maxBlocks;
}

public void setMouseX(int mouseX) {
    this.mouseX = mouseX;
}

public void setMouseY(int mouseY) {
    this.mouseY = mouseY;
}

}

And this is my code for Screen class:

public class Screen extends SurfaceView implements Callback

{

private Map map;
private SurfaceHolder holder;
private GameThread gamethread;
private Penguin penguin;
private boolean isSurfaceCreated;
private Bitmap tiles, character;
private int tileRows, tileColumns, minBlocks, maxBlocks;

public Screen(Context context, AttributeSet attb) {
    super(context, attb);
    tiles = BitmapFactory.decodeResource(getResources(), R.drawable.tile_sprites);
    character = BitmapFactory.decodeResource(getResources(), R.drawable.penguin_sprite);
    this.getHolder().addCallback(this);
    this.tileRows = new Game().getTileRows();
    this.tileColumns = new Game().getTileColumns();
    this.minBlocks = new Game().getMinBlocks();
    this.maxBlocks = new Game().getMaxBlocks();
}

}

Your help will be deeply appreciated 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:59:00+00:00Added an answer on May 31, 2026 at 6:59 pm

    Activity classes aren’t supposed to be instantiated by your code; they are created/re-used as needed when you use Intents. When you create a new Game(), there’s no intent associated with that and thus the getExtras calls in its constructor don’t find the integers you’re looking for–thus everything coming up as 0.

    If you know Screen objects are only used by the Game activity, you could cast your context to Game and then call the getters directly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass around some values in an array that will always be
I want to pass my renderer some values from another class. After the renderer
I want to call an ASHX file and pass some query string variables from
Im trying to pass some values into a text box from a child page
I want to pass some values to different forms at there button click event.
I have two tables and want to insert some column values from ane table
so i am using json to pass some information from one place to another...
I want to pass some parameters to my MVC UserControl like ShowTitle(bool) and the
I am writing an android app. I want to pass some data across the
I'm playing with the flickr api and php. I want to pass some information

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.