Hey there! any question in your mind? Ask It Now!.

Popular Categories

How Can I Declare Global Variable in Android

+1 vote
asked in Programming by jazs (1,220 points)
I am new in Android and working on username and password field should not visible if user has logged in successfully, so want to know how to set a global variable here, if you have any idea or any example code for login form please share here .
Thanks for help!

1 Answer

+2 votes
answered by amit_pammu Expert (5,030 points)
selected by jazs
Best answer
Just extend the android.app.Application class and add member
variables on it like the below example:
public class Android extends Application {
    private String strVariable1;
    public String getstrVariable1() {
return strVariable1;
    public void setstrVariable1(String strVariable1) {
        this.strVariable1 = strVariable1;
Now you have to set variables like this:
// set
((Android) this.getApplication()).setstrVariable1("Test");
// get
String s = ((Android) this.getApplication()).getstrVariable1();
may be it will help you to understand !// Thanks !
commented by Eathen (1,930 points)
I think Mr. pammu is right, this is the good way to declare global variable.
commented by jazs (1,220 points)
Thanks Mr. pammu.

Related Questions

+1 vote
2 answers 302 views
+2 votes
1 answer 203 views
+2 votes
1 answer 176 views
+1 vote
1 answer 161 views
+5 votes
1 answer 203 views
+1 vote
0 answers 79 views
+7 votes
2 answers 759 views
+8 votes
1 answer 243 views

Not a Member yet?

Ask to Folks Login

My Account
310 Folks are online
0 members and 310 guest online
Your feedback is highly appreciated