+1 vote
726 views
in Programming by (1.2k 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!
closed

1 Answer

+2 votes
by Expert (5.1k points)
selected by
 
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 !
0
by (1.9k points)
I think Mr. pammu is right, this is the good way to declare global variable.
0
by (1.2k points)
Thanks Mr. pammu.

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated