when i am calling my function with the parameter (URL and prams) its not returning login inside the result in main activity. its returning null then it implement the toast and then it continues and the implement my function.
please any help to let the function be the first one in the implementation
public class MainActivity extends AppCompatActivity {
private String URLline = "https://demonuts.com/Demonuts/JsonTest/Tennis/simplelogin.php";
private EditText etUname, etPass;
private Button btn;
public static String firstName, hobby,myresponse,myresponse2,result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etUname = findViewById(R.id.etusername);
etPass = findViewById(R.id.etpassword);
btn = findViewById(R.id.btn);
final Map<String,String> params2 = new HashMap<String, String>();
params2.put("PARAM1","AAA");
params2.put("PARAM2","ABC");
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
result=loginUser(URLline,params2);
Toast.makeText(MainActivity.this,result,Toast.LENGTH_LONG).show();
Toast.makeText(MainActivity.this,"Hellooooooo",Toast.LENGTH_LONG).show();
}
});
}
private String loginUser(String URL, final Map params2){
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(MainActivity.this,response,Toast.LENGTH_LONG).show();
myresponse =response;
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this,error.toString(),Toast.LENGTH_LONG).show();
}
}
)
{
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.putAll(params2);
return params;
}
};
stringRequest.setRetryPolicy(new DefaultRetryPolicy(200000, -1, 0));
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
if (myresponse != null)
{
myresponse=myresponse.replaceAll("//r//n","");
myresponse=myresponse.replaceAll("//","");
myresponse=myresponse.substring(1,myresponse.length()-2);
}
return myresponse;
}
}