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

Popular Categories





How Can I Declare Global Variable in Android

+1 vote
242 views
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:
 
#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

0 votes
0 answers 466 views
0 votes
0 answers 269 views
+1 vote
2 answers 236 views
+2 votes
1 answer 122 views
+2 votes
1 answer 150 views
+1 vote
1 answer 113 views
+5 votes
1 answer 142 views
asked in Programming by jatin Expert (3,823 points)
+1 vote
0 answers 47 views
+7 votes
2 answers 618 views
+8 votes
1 answer 120 views

Not a Member yet?

Ask to Folks Login

My Account
450 Folks are online
2 members and 448 guest online
Your feedback is highly appreciated