I am following a tutorial which adds data to remote sql database, I get the above error and on some occasions the "endAllStagingAnimators" errors,The app uses AsyncTask so how come it still gives the above error??
MainActivity:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void userReg(View view) {
startActivity(new Intent(this,Register.class));
}
}
AsyncTask class BackgroundTask:
public class BackgroundTask extends AsyncTask{
Context context;
BackgroundTask(Context context) {
this.context= context;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Object doInBackground(Object[] params) {
String url_reg= "http://192.168.1.1/webapp/register.php";
String url_login= "http://192.168.1.1/webapp/login.php";
String method= (String) params[0];
if (method.equals("register")) {
String name= (String) params[1];
String user_name= (String) params[2];
String user_pass= (String) params[3];
try {
URL url= new URL(url_reg);
HttpURLConnection httpURLConnection= (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
OutputStream os= httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter= new BufferedWriter(new OutputStreamWriter(os,"UTF-8"));
String Data=(URLEncoder.encode("user", "UTF-8") + "=" + URLEncoder.encode(name, "UTF-8") + "&" +
URLEncoder.encode("user_name", "UTF-8") + "=" + URLEncoder.encode(user_name, "UTF-8") +
URLEncoder.encode("user_pass", "UTF-8") + "=" + URLEncoder.encode(user_pass, "UTF-8"));
bufferedWriter.write(Data);
bufferedWriter.flush();
bufferedWriter.close();
os.close();
InputStream is= httpURLConnection.getInputStream();
is.close();
return "Registration Success";
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
@Override
protected void onProgressUpdate(Object[] values) {
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(Object o) {
Toast.makeText(context,o.toString(),Toast.LENGTH_LONG);
}
}
Register Class:
public class Register extends Activity {
EditText et_name,et_user_name,et_user_pass;
Button btn_register;
String name,userName,userPass;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register_layout);
et_name= (EditText) findViewById(R.id.et_regname);
et_user_name= (EditText) findViewById(R.id.et_regusername);
et_user_pass= (EditText) findViewById(R.id.et_regpass);
btn_register= (Button) findViewById(R.id.btn_register);
}
public void userReg(View view) {
name= et_name.getText().toString();
userName= et_user_name.getText().toString();
userPass= et_user_pass.getText().toString();
String method= "register";
BackgroundTask backgroundTask= new BackgroundTask(this);
backgroundTask.execute(method,name,userName,userPass);
finish();
}
}
Logcat:
12-18 16:35:49.818 1964-1980/hilz.mysqldemo W/EGL_emulation: eglSurfaceAttrib not implemented
12-18 16:35:49.818 1964-1980/hilz.mysqldemo W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa502f580, error=EGL_SUCCESS
12-18 16:35:55.058 1964-1964/hilz.mysqldemo I/Choreographer: Skipped 312 frames! The application may be doing too much work on its main thread.
Manifest File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="hilz.mysqldemo" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Register" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category." />
</intent-filter>
</activity>
</application>
</manifest>