I have a problem with passing data(values) from java class to activity and display it in textView. Sharedpreferences is not working. This is fragment from my class:
else if (type.equals("getUser")) {
try {
String user_name = params[1];
// String password = params[2];
URL url = new URL(getUser_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_name", "UTF-8") + "=" + URLEncoder.encode(user_name, "UTF-8") + "&"
// + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(password, "UTF-8");
String post_data = URLEncoder.encode("user_name", "UTF-8") + "=" + URLEncoder.encode(user_name, "UTF-8");
bufferedWriter.write(post_data);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
String result = "";
String line = "";
while ((line = bufferedReader.readLine()) != null) {
result += line;
}
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
System.out.println(result);
return result;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
@Override
protected void onPostExecute(String result) {
String temp = "Login success. Welcome!";
if (result.equals(temp)) {
Intent intent = new Intent(context, ProjectsActivity.class);
context.startActivity(intent);
} else if (result.contains("[{")) {
} else {
alertDialog.setMessage(result);
alertDialog.show();
}
}
and I want to pass my result to textview in activity. This activity (UserAreaActivity).
public class UserAreaActivity extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_area);
TextView textViewUserArea = (TextView) findViewById(R.id.textViewUserArea);
EditText editTextName = (EditText) findViewById(R.id.editTextName);
EditText editTextSurname = (EditText) findViewById(R.id.editTextrSurname);
EditText editTextUsername = (EditText) findViewById(R.id.editTextUsername);
EditText editTextPassword = (EditText) findViewById(R.id.editTextPassword);
EditText editTextAge = (EditText) findViewById(R.id.editTextAge);
//
String type = "getUser";
BackgroundWorker backgroundWorker = new BackgroundWorker(this);
backgroundWorker.execute(type, username);
}
Thanks a lot for any help.