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

  • Home
  • SEARCH
  • 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 6885103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:35:34+00:00 2026-05-27T05:35:34+00:00

Note: I don’t talk about sharing variables between Activities or the need to save

  • 0

Note: I don’t talk about sharing variables between Activities or the need to save them permanently.

I’m developing an app that uses a 3D-Engine. All my rendering takes place in one renderer class. I have several objects (such as a camera, a light, a framebuffer) which I need in several methods and have therefore declared them as class members:

public class Renderer{
//..
private Camera camera = null;
private Light sun = null;
private Matrix someMatrix = new Matrix();

private void onSurfaceChanged(GL10 gl, int width, int height){
    //...
    sun = new Light(x,y,z,color);
    camera = new Camera(arg1, arg2);
}

public void onDrawFrame(GL10 arg0) {

    someMatrix = getRandomValues();
    //...

}

}   

Is this the “correct” way to do this? Or should I rather pass the objects via method arguments? Of course I could declare someMatrix also in onDrawFrame, but since resources are not plentyful on mobile devices, I rather not have them initialized each time onDrawFrame is called. The problem I have now, is that I really have a lot class variables, which I normally would consider as bad style. I couldn’t find anything about this topic in the style guidelines for Android. Are there alternatives which improve readability and/or safety?

  • 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-27T05:35:35+00:00Added an answer on May 27, 2026 at 5:35 am

    This is the correct way of doing so, yes.

    Nothing more to add, really.

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

Sidebar

Related Questions

NOTE: I don't think this is a duplicate of the billion other questions about
NOTE: I'm ultra-newbie on algorithm analysis so don't take any of my affirmations as
Note The question below was asked in 2008 about some code from 2003. As
Note:I don't mean some theoretical question which don't have any implementation just languages that
How to show two fieldsets horizontally in a form? Note: I don't mean show
Note: I don't want to attach the Image to the Email I want to
Having a PrintTicket how to display the printer-specific configuration dialog? Note: I don't mean
Note: I don't do .NET programming regularly. Normally I do native/MFC, so I'm a
I'm parsing a file format with a header. (Note: I don't write any files,
What exactly does Environment.ExternalStorageDirectory return? I read from the developer docs: Note: don't be

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.