0

In Reminder1.java I have the int hourOfDay2 and int minute2 variables. These equals with the hourOfDay and minute variable of the TimePickerDialog. In myfile.java i want to examine the value of these variables. How to do that?

2
  • 2
    Start here -- happy coding. Commented Jan 25, 2011 at 21:39
  • You need to explain more. Do you have an instance of the Reminder1 class in your myfile class? Are they static ints? Are either of these classes Activities or extending some other Android class? Commented Jan 25, 2011 at 21:40

2 Answers 2

4

One thing I've seen posted here on SO a few times, and that I've used for global variables, is an extended Application class, like so:

public class GlobalVars extends Application {
    private static int hourOfDay2;
    private static int minute2;

    public static int getHourOfDay() {
        return hourOfDay2;
    }

    public static int getMinute() {
        return minute2;
    }

    public static void setHourOfDay(int hour) {
        hourOfDay2 = hour;
    }

    public static void setMinute(int minute) {
        minute2 = minute;
    }
}

Add it to your Application tag in the manifest, like so:

<application android:name=".GlobalVars" />

Then, in your main class's onCreate, or wherever necessary, just call GlobalVars.setMinute(int) to initialize them, then you can access them the same way in any other class, with int x = GlobalVars.getMinute().

Sign up to request clarification or add additional context in comments.

1 Comment

@Jems: Heh, yeah most likely. I don't have Eclipse at the moment, so it slipped my mind. :) fixed, thanks.
0

In android, you can use Bundle to pass values.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.