I have this method:
public String comprovarLogin(String usuari, String contrasenya){
final String metode = "comprovarLogin";
String ret = null;
try{
//Preparem els arguments del mètode compovarLogin
Map<String,String> args = new HashMap<>();
args.put("usuari",usuari);
args.put("contrasenya",contrasenya);
//Fem la crida al mètode per obtenir-ne la resposta
SoapObject respostaSoap = usarWebService(metode,args);
//Retornem el valor de "authId"
System.out.println(respostaSoap.getPrimitiveProperty("authId"));
}
catch(Exception ex){
ex.printStackTrace();
ret = "ERROR_CRIDA";
}
return ret;
}
in the WbServiceCalls class
The issue is that from another class called Xxxxxxx
I do the following:
WebServiceCalls calls = new WebServiceCalls();
System.out.println(calls.comprovarLogin(usuari, usuariContrasenya));
I call the checkLogin method and pass it two values.
So far perfect. But I would be interested in being able to use the variable respostaSoap.getPrimiteProperty("authId") from the webserviceCalls class to do things with it from the xxxxxxx class.
How can I do it?
The idea is to do an if/else to check that the authId value is, for example, the name "Dani".
Thanks.
PS: My idea would be to do something like this:
WebServiceCalls calls = new WebServiceCalls();
System.out.println(calls.comprovarLogin(usuari, usuariContrasenya));
//comprobar authId
if (Authid.equalsIgnoreCase("Dani"){
bla bla bla
{
}else{
bla bla
}
I find it curious that you return null when all is well and an error message that doesn't really say anything special when login fails. Why don't you return what you need?:
The usage would be something like:
I tell you...
There are several ways to do what you say, but for what you want to do this can help you:
public static string authId = "";
This allows you to access it from another class, remembering that the class must be public. Note: remember that static variables have a lifetime that extends throughout the execution of the program. Now assign the value you want to that variable so that it persists during the execution of the program, example:authId = respostaSoap.getPrimitiveProperty("authId");
.String strAuthId = Actual.authId;
o use a getter method.I share your code with the aforementioned:
As I told you at the beginning, you have several ways to do it, I hope it helps you to get an idea,
Luck...