The asynchronous operation is no longer available. So I want to use RxJava instead. However, no matter how much I search on Google, there is no way to convert it. Among the 'Mainactivitie' that I uploaded, if you press the button assigned to 'btn_user', the screen changes and the information stored in mysql is displayed through the php file written in 'target'. How can I change it? Or is there anything I can use other than RxJava? Do not use kotlin. If you need more files, I will provide them to you.
I'll mark the parts that need to be changed. //---- From //----
public class MainActivity extends AppCompatActivity {
private TextView tv_id, tv_pass;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv_id = findViewById(R.id.tv_id);
tv_pass = findViewById(R.id.tv_pass);
Button btn_user = (Button) findViewById(R.id.btn_user);
Intent intent = getIntent();
String id = intent.getStringExtra("id");
String pass = intent.getStringExtra("pass");
tv_id.setText(id);
tv_pass.setText(pass);
if(!id.equals("admin"))
{
btn_user.setVisibility(View.GONE);
}
//----------------------------------------------------------------
btn_user.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
new BackgroundTask().execute();
}
});
}
class BackgroundTask extends AsyncTask<Void, Void, String> {
String target;
@Override
protected void onPreExecute() {
target = "http://MyIP/phpFile.php";
}
@Override
protected String doInBackground(Void... voids) {
try {
URL url = new URL(target);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String temp;
StringBuilder stringBuilder = new StringBuilder();
while ((temp = bufferedReader.readLine()) != null) {
stringBuilder.append(temp + "\n");
}
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return stringBuilder.toString().trim();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(String result) {
Intent intent = new Intent(MainActivity.this, ManagementActivity.class);
intent.putExtra("userList", result);
MainActivity.this.startActivity(intent);
}
}
//----------------------------------------------------------
}