I have code to registery witch one can return me 1 when registery is succes and 2 when is not. And i want to open new activity when registery was succes. But if i make if (result == "1) it was not working :/ I add this in onPostExecute. How i can add open new activity when registery was succes?
@Override
protected String doInBackground(String... params) {
String type = params[0];
String registery_url = "http://server/registery.php";
if(type.equals("registery")){
try {
String user_login = params[1];
String user_email = params[2];
String user_password = params[3];
String user_password2 = params[4];
URL url = new URL(registery_url);
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
String post_data = URLEncoder.encode("user_login", "UTF-8")+"="+URLEncoder.encode(user_login, "UTF-8")+"&"
+URLEncoder.encode("user_email", "UTF-8")+"="+URLEncoder.encode(user_email, "UTF-8")+"&"
+URLEncoder.encode("user_password", "UTF-8")+"="+URLEncoder.encode(user_password, "UTF-8")+"&"
+URLEncoder.encode("user_password2", "UTF-8")+"="+URLEncoder.encode(user_password2, "UTF-8");
bufferedWriter.write(post_data);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
String result = "";
String line="";
while((line=bufferedReader.readLine())!=null){
result+=line;
}
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return result;
}
catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPreExecute() {
alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("Registery status");
}
@Override
protected void onPostExecute(String result) {
alertDialog.setMessage(result);
alertDialog.show();
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
}