-1
I am creating a login system on Android, but for some reason is giving me this error:
Skipped 280 frames! The application may be Doing Too Much work on its main thread.
Can someone help me?
package imm.pt.immsmart;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.StrictMode;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.util.ArrayList;
public class Login extends AppCompatActivity {
public void entrar(View view){
TextView user = (TextView) findViewById(R.id.mail);
TextView pass = (TextView) findViewById(R.id.password);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://192.168.1.66/immsmart/api.php");
try {
ArrayList<NameValuePair> valores = new ArrayList<NameValuePair>();
valores.add(new BasicNameValuePair("task", "login"));
valores.add(new BasicNameValuePair("mail", user.getText().toString()));
valores.add(new BasicNameValuePair("pass", pass.getText().toString()));
httpPost.setEntity(new UrlEncodedFormEntity(valores));
final HttpResponse resposta = httpClient.execute(httpPost);
String res = EntityUtils.toString(resposta.getEntity());
if(res.equals("notfound")) {
user.setText("");
pass.setText("");
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setMessage("Dados Invalidos!");
builder.create();
}else{
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setMessage(res);
builder.create();
Intent mainIntent = new Intent(Login.this, Menu.class);
Login.this.startActivity(mainIntent);
Login.this.finish();
}
}catch (ClientProtocolException e){} catch (IOException e) {}
}
}