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 6533475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:07:53+00:00 2026-05-25T10:07:53+00:00

I’m still struggling to find a clean easy way to load some values in

  • 0

I’m still struggling to find a clean easy way to load some values in my onCreate method and pass them to another class in order that a game may load and save option settings.

I can successfully retrieve and change values from my other class but the problem is, no matter what I try, variable set in the onCreate method will not carry to the rest of the code.

I take the point that by only showing snipits of the code I may have obscured the problem but my original is far to massive and sprawling to post HOWEVER it was based on a great tutorial by Martin
http://www.droidnova.com/android-3d-game-tutorial-part-i,312.html

So I’ve returned to first principles and just added the problematic portion to that tutorial code and my problem has been replicated. So here is the complete code:

Vortex.java **

package com.clockworkrobot.vortex;

import android.app.Activity;
import android.os.Bundle;

public class Vortex extends Activity {
    private static final String LOG_TAG = Vortex.class.getSimpleName();
    private VortexView _vortexView;

    private float _red ;  // these are the values that actually reach VortexRender class
    private float _green = 1f ; // touch the screen, it will turn green.
    private float _blue ;  // but why don't the variable in my onCreate override these?

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        _red = 1f;    // The test values I want to reach my Vortex Renderer class.
        _green = 0f;  // to help debug. they should make the screen magenta
        _blue = 1f;  // Eventually these value will be loaded during onCreate

       setRed(_red);  // I don't think these are needed 
       setGreen(_green); // But since the variable within this method
       setBlue(_blue); // don't appear to be reaching their target..worth a try

        _vortexView = new VortexView(this);
        setContentView(_vortexView);
    }

    public float getRed() {
        return _red;       
    }

    public void setRed(float value) {
        _red = value;
    }

    public float getGreen() {
        return _green;       
    }

    public void setGreen(float value) {
        _green = value;
    }

    public float getBlue() {
        return _blue;       
    }

    public void setBlue(float value) {
        _blue = value;
    }


}

VortexRender.java**

package com.clockworkrobot.vortex;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;

public class VortexRenderer extends Activity implements GLSurfaceView.Renderer {
private static final String LOG_TAG = VortexRenderer.class.getSimpleName();

 //   Vortex sw = new Vortex();

private Vortex sw;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    sw = new Vortex();
}

    private float _red = 0f;
    private float _green = 0f;
    private float _blue = 0f;

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        // Do nothing special.
    }

    @Override
    public void onSurfaceChanged(GL10 gl, int w, int h) {
        gl.glViewport(0, 0, w, h);
    }

    @Override
    public void onDrawFrame(GL10 gl) {
        // define the color we want to be displayed as the "clipping wall"
        gl.glClearColor(_red, _green, _blue, 1.0f);
        // clear the color buffer to show the ClearColor we called above...
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    }

    public void setColor(float r, float g, float b) {

        _red = sw.getRed();     // Want these to grab the values from my onCreate method
        _green = sw.getGreen(); // But instead it's getting the nul values
        _blue = sw.getBlue();   // eg values as set above me onCreate.

//        _red = r;
//        _green = g;
//        _blue = b;

    }
}

VortexView.java**

package com.clockworkrobot.vortex;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.view.MotionEvent;

public class VortexView extends GLSurfaceView {
    private static final String LOG_TAG = VortexView.class.getSimpleName();
    private VortexRenderer _renderer;

    public VortexView(Context context) {
        super(context);
        _renderer = new VortexRenderer();
        setRenderer(_renderer);
    }

    public boolean onTouchEvent(final MotionEvent event) {
        queueEvent(new Runnable() {
            public void run() {
                _renderer.setColor(event.getX() / getWidth(), event.getY() / getHeight(), 1.0f);
            }
        });
        return true;
    }
}

AndroidManifest.xml**

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.clockworkrobot.vortex"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Vortex"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="3" />
</manifest> 

In essence.. What I require is a way to save and recover the current screen colour when the game opens and closes.
Thanks to everyone who has helped so far.

  • 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-25T10:07:53+00:00Added an answer on May 25, 2026 at 10:07 am

    I’m still struggling to find a clean easy way to load some values in my onCreate method and pass them to another class in order that a game may load and save option settings.

    Use SharedPreferences — that is why they are there.

    Anyone got any helpful ideas?

    Either:

    • Your other class is not talking to the Activity object you think it is, or
    • You are not calling the code in the other class that invokes your setter, or
    • Your activity is being recreated (e.g., configuration change) as part of your testing, or
    • As @Arnout Engelen notes, you are calling the setter from multiple places and are overwriting what you want, or
    • Something else, since the code you have above most likely is not really the code from your app, and fake examples like this just cause problems when you go to ask people for help, because you introduce differences between what you’re really running and what you’re claiming you’re running

    UPDATE
    You are creating a Vortex via new Vortex(). Vortex is an Activity. Never create activities via the constructor. You do not access activities from other activities. Your red/green/blue values need to be in some data model accessible from all your components.

    Given your code and comments, I strongly encourage you to first learn Java outside of Android, then learn Android.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am confused How to use looping for Json response Array in another Array.
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I need to clean up various Word 'smart' characters in user input, including but
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.