None of the ToastMessages in this code are shown.
private final class FetchUrlLINKTOINCREASECOIN extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
try {
Toast.makeText(MainActivity.this, "THIS IS NOT SHOWN", Toast.LENGTH_SHORT).show();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://example.com/xx.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("userid", f12139v0));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity, "UTF-8");
Pattern pattern = Pattern.compile(",\"postid\":\"(.*?)\",\"");
Matcher matcher = pattern.matcher(responseString);
if (matcher.find())
{
String req_id = matcher.group(1);
Toast.makeText(MainActivity.this, req_id, Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(MainActivity.this, "n", Toast.LENGTH_SHORT).show();
}
Toast.makeText(MainActivity.this, responseString, Toast.LENGTH_SHORT).show();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
} catch (Exception e) {
}
return "executed";
}
}
But the web request is fine. This is how i run this function:
Toast.makeText(MainActivity.this, "This is fine", Toast.LENGTH_SHORT).show();
new FetchUrlLINKTOINCREASECOIN().execute();
As you can see i put a toastmessage before running the function and the app showed that.