Reputation: 337
In android I've to achieve following:
If entered password is correct in funToEnterPassword();
. How could I know here from which method I called this method so I can continue with functionABC();
or functionXYZ();
public void fun1(){
funToEnterPassword();
funcABC();
}
public void fun1(){
funToEnterPassword();
functionXYZ();
}
public void funToEnterPassword(){
//Enter password in popup
//If password is correct how could I know here from which method I got called this method so I can continue with functionABC() or functionXYZ();
}
Upvotes: 0
Views: 91
Reputation: 721
Usually the third item in the array should hold the current class and method values! this below code could be of some use!
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
if(stackTraceElements != null && stackTraceElements.length > 0){
if(stackTraceElements.length > 2){
String methodName = stackTraceElements[2].getMethodName();
String className = stackTraceElements[2].getClassName();
Log.e(className, methodName);
Toast.makeText(this, className + " " + methodName, Toast.LENGTH_LONG).show();
}
}
Upvotes: 0
Reputation: 28823
Try following method:
public void fun1(){
boolean result = funToEnterPassword();
if (result)
funcABC();
}
public void fun2(){
boolean result = funToEnterPassword();
if (result)
functionXYZ();
}
public boolean funToEnterPassword(){
pwdResult = false;
//Enter password in popup
//If correct pwd
pwdResult = true;
//If password is correct how could I know here from which method I got called this method so I can continue with functionABC() or functionXYZ();
return pwdResult;
}
Upvotes: 1
Reputation: 490
You can use boolean for that either declare method type as boolean or a variable and sets its value as you needed. Simple. :)
Upvotes: 2