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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:27:56+00:00 2026-05-23T10:27:56+00:00

I know this question has been asked a million times because I have done

  • 0

I know this question has been asked a million times because I have done some research and have found many threads on this. I have tried to use the answers in those threads but I am having a bit of trouble.

I am looking to set a few variables that I can use across all of my activities.

I created a GlobalVariables.java class which looks like the following (the value in there is just for testing purposes as of now):

import android.app.Application;

public class GlobalVariables extends Application {

int holeAmount;

public int getHoles(){
    return holeAmount;
  }
  public void setHoles(String s){
    holeAmount = 30;
  }

}

in my main activity where everything is happening I have the following:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    GlobalVariables global = ((GlobalVariables)getApplicationContext());
    int totalHoles = global.getHoles();

and on the “GlobalVariables global = …” line I am getting the following error:

Multiple markers at this line
- GlobalVariables cannot be resolved 
 to a type
- GlobalVariables cannot be resolved 
 to a type

I tried to follow the instructions here but clearly I am doing something incorrectly. > How to declare global variables in Android?

Any help would be greatly appreciated!

Thanks!



SECOND ATTEMPT:

EasyPar.java (Errors @ EasyParHelperActivity)

package com.movi.easypar;

import java.text.DateFormat;
import java.util.Date;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

public class EasyPar extends Activity implements OnClickListener {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

(initialize all my buttons and textviews)
}

public void someMethod() {
    EasyParHelperActivity.helper.setHoles(30);
    int holes = EasyParHelperActivity.helper.getHoles();
}

(the rest of my button functions, etc.)

EasyParHelperActivity (No Errors)

package com.movi.easypar;

import android.app.Application;

public class EasyParHelperActivity extends Application {

public static EasyParHelper helper = new EasyParHelper();

}

EasyParHelper.java (No Errors)

package com.movi.easypar;

public class EasyParHelper {

private int holeAmount = 0;

public int getHoles() {
    return holeAmount;
}

public void setHoles(int holes) {
    holeAmount = holes;
}
}

All i want is for the user to be able to click a button “18” or “9” on the first screen, and for the application to be able to use that value other times throughout whatever it does. So I need to set it in screen 1, and in screen 2 i need to retrieve that value.

  • 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-23T10:27:57+00:00Added an answer on May 23, 2026 at 10:27 am

    Create a ‘helper’ class as follows…

    package com.my.application
    
    public class MyAppHelper {
    
        private int holeAmount = 0;
    
        public int getHoles() {
            return holeAmount;
        }
    
        public void setHoles(int holes) {
            holeAmount = holes;
        }
    }
    

    Then for your Application class do the following…

    package com.my.application
    
    public class MyApplication extends Application {
    
        public static MyAppHelper helper = new MyAppHelper();
    
    }
    

    To get access to the get/set methods in the helper you can simply call…

    package com.my.application
    
    public class MyActivity extends Activity {
    
        // Normal onCreate(...) etc here
    
        public void someMethod() {
            MyApplication.helper.setHoles(30);
            int holes = MyApplication.helper.getHoles();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been asked many and many times, but I have
I know this question has been asked a million times in one form or
I know this question has been asked a million of times here at stackoverflow,
I know this question has been asked a million times in various ways by
I know this question has been asked quite a few times, however, I have
I know this question has been asked many times, and I've searched stackoverflow and
I know this question has been asked many times and I've researched it myself
I know this question has been asked many times, but I am having trouble
I know this question has been asked many times. But from what I read,
Hey all, I know this question has been asked a million times before but

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.