Dont use AsyncTask
This commit is contained in:
parent
2ee3603229
commit
b361fad52d
@ -1,6 +1,5 @@
|
|||||||
package com.example.lfrmobileapp.ui.notifications;
|
package com.example.lfrmobileapp.ui.notifications;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -8,7 +7,6 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@ -17,9 +15,38 @@ import androidx.lifecycle.ViewModelProvider;
|
|||||||
|
|
||||||
import com.example.lfrmobileapp.Communication;
|
import com.example.lfrmobileapp.Communication;
|
||||||
import com.example.lfrmobileapp.DataTransferAsyncTask;
|
import com.example.lfrmobileapp.DataTransferAsyncTask;
|
||||||
import com.example.lfrmobileapp.R;
|
|
||||||
import com.example.lfrmobileapp.databinding.FragmentEinstellungenBinding;
|
import com.example.lfrmobileapp.databinding.FragmentEinstellungenBinding;
|
||||||
|
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.net.Socket;
|
||||||
|
|
||||||
|
|
||||||
|
/*class NetworkThread extends Thread {
|
||||||
|
String ip;
|
||||||
|
int port;
|
||||||
|
boolean connected;
|
||||||
|
|
||||||
|
NetworkThread(String ip, int port) {
|
||||||
|
this.ip = ip;
|
||||||
|
this.port = port;
|
||||||
|
this.connected = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Socket socket = new Socket(ip, port);
|
||||||
|
DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());
|
||||||
|
outputStream.writeBytes("Verbindung aufbauen");
|
||||||
|
outputStream.flush();
|
||||||
|
socket.close();
|
||||||
|
connected = true;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
connected = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
public class NotificationsFragment extends Fragment {
|
public class NotificationsFragment extends Fragment {
|
||||||
|
|
||||||
@ -70,11 +97,24 @@ public class NotificationsFragment extends Fragment {
|
|||||||
ipAddress = String.valueOf(binding.ipAdress.getText());
|
ipAddress = String.valueOf(binding.ipAdress.getText());
|
||||||
port = Integer.parseInt(String.valueOf(binding.port.getText()));
|
port = Integer.parseInt(String.valueOf(binding.port.getText()));
|
||||||
|
|
||||||
dataTransferAsyncTask = new DataTransferAsyncTask(ipAddress, port);
|
new Thread(new Runnable(){
|
||||||
dataTransferAsyncTask.writeTelegram("Verbindung aufbauen");
|
public void run(){
|
||||||
dataTransferAsyncTask.execute();
|
try {
|
||||||
|
Socket socket = new Socket(ipAddress, port);
|
||||||
|
DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());
|
||||||
|
outputStream.writeBytes("Verbindung aufbauen");
|
||||||
|
outputStream.flush();
|
||||||
|
socket.close();
|
||||||
|
connected = true;
|
||||||
|
|
||||||
if(dataTransferAsyncTask.getConnectionState()){
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
connected = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
if(connected){
|
||||||
editor.putString(ipKey, ipAddress);
|
editor.putString(ipKey, ipAddress);
|
||||||
editor.putInt(portKey, port);
|
editor.putInt(portKey, port);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user