File tree Expand file tree Collapse file tree 7 files changed +160
-23
lines changed
app/src/main/java/com/example/chatfull Expand file tree Collapse file tree 7 files changed +160
-23
lines changed Original file line number Diff line number Diff line change
1
+
2
+ # Created by https://www.gitignore.io/api/android
3
+ # Edit at https://www.gitignore.io/?templates=android
4
+
5
+ # ## Android ###
6
+ # Built application files
7
+ * .apk
8
+ * .ap_
9
+ * .aab
10
+
11
+ # Files for the ART/Dalvik VM
12
+ * .dex
13
+
14
+ # Java class files
15
+ * .class
16
+
17
+ # Generated files
18
+ bin /
19
+ gen /
20
+ out /
21
+ release /
22
+
23
+ # Gradle files
24
+ .gradle /
25
+ build /
26
+
27
+ # Local configuration file (sdk path, etc)
28
+ local.properties
29
+
30
+ # Proguard folder generated by Eclipse
31
+ proguard /
32
+
33
+ # Log Files
34
+ * .log
35
+
36
+ # Android Studio Navigation editor temp files
37
+ .navigation /
38
+
39
+ # Android Studio captures folder
40
+ captures /
41
+
42
+ # IntelliJ
1
43
* .iml
2
- .gradle
3
- /local.properties
4
- /.idea /caches
5
- /.idea /libraries
6
- /.idea /modules.xml
7
- /.idea /workspace.xml
8
- /.idea /navEditor.xml
9
- /.idea /assetWizardSettings.xml
10
- .DS_Store
11
- /build
12
- /captures
44
+ .idea /workspace.xml
45
+ .idea /tasks.xml
46
+ .idea /gradle.xml
47
+ .idea /assetWizardSettings.xml
48
+ .idea /dictionaries
49
+ .idea /libraries
50
+ # Android Studio 3 in .gitignore file.
51
+ .idea /caches
52
+ .idea /modules.xml
53
+ # Comment next line if keeping position of elements in Navigation Editor is relevant for you
54
+ .idea /navEditor.xml
55
+
56
+ # Keystore files
57
+ # Uncomment the following lines if you do not want to check your keystore files in.
58
+ # *.jks
59
+ # *.keystore
60
+
61
+ # External native build folder generated in Android Studio 2.2 and later
13
62
.externalNativeBuild
63
+
64
+ # Google Services (e.g. APIs or Firebase)
65
+ # google-services.json
66
+
67
+ # Freeline
68
+ freeline.py
69
+ freeline /
70
+ freeline_project_description.json
71
+
72
+ # fastlane
73
+ fastlane /report.xml
74
+ fastlane /Preview.html
75
+ fastlane /screenshots
76
+ fastlane /test_output
77
+ fastlane /readme.md
78
+
79
+ # Version control
80
+ vcs.xml
81
+
82
+ # lint
83
+ lint /intermediates /
84
+ lint /generated /
85
+ lint /outputs /
86
+ lint /tmp /
87
+ # lint/reports/
88
+
89
+ # ## Android Patch ###
90
+ gen-external-apklibs
91
+ output.json
92
+
93
+ # End of https://www.gitignore.io/api/android
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ public class ChatActivity extends AppCompatActivity {
23
23
User user ;
24
24
ArrayList <String > received_message = new ArrayList <>();
25
25
SendMessage sender ;
26
+ MessageReceiveServer messageReceiveServer ;
26
27
27
28
@ Override
28
29
protected void onCreate (Bundle savedInstanceState ) {
@@ -38,7 +39,7 @@ protected void onCreate(Bundle savedInstanceState) {
38
39
messageDisplay .setText ("Connected to: " + user .getIpAddress () + ":" + user .getPort () + "\n " );
39
40
messageDisplay .append ("Self: " + ShowInfoActivity .getSelfIpAddress () + ":" + ShowInfoActivity .getSelfPort ());
40
41
41
- new MessageReceiveServer (ShowInfoActivity .getSelfIpAddress (),ShowInfoActivity .getSelfPort (),this );
42
+ messageReceiveServer = new MessageReceiveServer (ShowInfoActivity .getSelfIpAddress (),ShowInfoActivity .getSelfPort (),this );
42
43
}
43
44
44
45
public void OnMsgSendBtnClick (View view ){
@@ -61,4 +62,11 @@ public void run() {
61
62
}
62
63
});
63
64
}
65
+
66
+ @ Override
67
+ protected void onDestroy () {
68
+ super .onDestroy ();
69
+ sender .cancel (true );
70
+ messageReceiveServer .onDestroy ();
71
+ }
64
72
}
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ public class ConnectToUserActivity extends AppCompatActivity {
15
15
Button connectBtn ;
16
16
Client myClient ;
17
17
User user ;
18
+ boolean paused = false ;
18
19
19
20
public void setUser (User user ) {
20
21
this .user = user ;
@@ -34,6 +35,21 @@ protected void onCreate(Bundle savedInstanceState) {
34
35
connectBtn = findViewById (R .id .connectBtn );
35
36
}
36
37
38
+ @ Override
39
+ protected void onResume () {
40
+ super .onResume ();
41
+ if (paused ) {
42
+ myClient .cancel (true );
43
+ recreate ();
44
+ }
45
+ }
46
+
47
+ @ Override
48
+ protected void onPause () {
49
+ super .onPause ();
50
+ paused = true ;
51
+ }
52
+
37
53
public void connectBtnListener (View view ){
38
54
myClient = new Client (ipInput .getText ().toString (),Integer .parseInt (portInput .getText ().toString ()),this );
39
55
myClient .execute ();
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ public class MessageReceiveServer{
13
13
int port ;
14
14
ChatActivity activity ;
15
15
ServerSocket serverSocket ;
16
+ boolean stop = false ;
16
17
int cnt = 0 ;
17
18
18
19
MessageReceiveServer (String ip_address , int port , ChatActivity activity ){
@@ -29,7 +30,7 @@ private class MessageSocketServerThread extends Thread {
29
30
public void run () {
30
31
try {
31
32
serverSocket = new ServerSocket (port );
32
- while (true ) {
33
+ while (stop == false ) {
33
34
cnt ++;
34
35
Log .e ("Abar" ,"" +cnt );
35
36
@@ -55,5 +56,15 @@ public void run() {
55
56
}
56
57
}
57
58
}
59
+ public void onDestroy (){
60
+ if (serverSocket != null ){
61
+ try {
62
+ serverSocket .close ();
63
+ stop = true ;
64
+ } catch (IOException e ) {
65
+ e .printStackTrace ();
66
+ }
67
+ }
68
+ }
58
69
59
70
}
Original file line number Diff line number Diff line change @@ -41,7 +41,6 @@ protected String doInBackground(Void... arg0) {
41
41
Log .e ("SendMSG" ,"ConnectHoyNai" +message );
42
42
e .printStackTrace ();
43
43
}
44
- // Thread.interrupted();
45
44
return "" ;
46
45
}
47
46
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ public class Server {
16
16
String self_ip_address ;
17
17
int self_port ;
18
18
public User user ;
19
+ boolean stop = false ;
19
20
20
21
public Server (ShowInfoActivity activity , String self_ip_address , int self_port ) {
21
22
this .activity = activity ;
@@ -33,7 +34,7 @@ public void run() {
33
34
// create ServerSocket using specified port
34
35
serverSocket = new ServerSocket (self_port );
35
36
36
- while (true ) {
37
+ while (stop == false ) {
37
38
// block the call until connection is created and return
38
39
// Socket object
39
40
Log .e ("Server" ,"InsideServer" );
@@ -67,20 +68,26 @@ public void run() {
67
68
activity .setConnected (true );
68
69
}
69
70
});
71
+ stop = true ;
70
72
break ;
71
73
}
72
74
} catch (IOException e ) {
73
75
// TODO Auto-generated catch block
74
76
e .printStackTrace ();
75
77
}
76
- if (serverSocket != null ) {
77
- try {
78
- Log .e ("Server" ,"Close Server" );
79
- serverSocket .close ();
80
- } catch (IOException e ) {
81
- // TODO Auto-generated catch block
82
- e .printStackTrace ();
83
- }
78
+ onDestroy ();
79
+ }
80
+ }
81
+
82
+ void onDestroy (){
83
+ if (serverSocket != null ) {
84
+ try {
85
+ Log .e ("Server" ,"Close Server" );
86
+ serverSocket .close ();
87
+ stop = true ;
88
+ } catch (IOException e ) {
89
+ // TODO Auto-generated catch block
90
+ e .printStackTrace ();
84
91
}
85
92
}
86
93
}
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ public class ShowInfoActivity extends AppCompatActivity {
17
17
18
18
static final int selfPort = 8080 ;
19
19
Server myServer ;
20
+ boolean paused = false ;
20
21
21
22
public void setConnected (boolean connected ) {
22
23
this .connected = connected ;
@@ -44,6 +45,21 @@ protected void onCreate(Bundle savedInstanceState) {
44
45
Log .e ("ShowActivity" ,"CreatedServer" );
45
46
}
46
47
48
+ @ Override
49
+ protected void onResume () {
50
+ super .onResume ();
51
+ if (paused ) {
52
+ myServer .onDestroy ();
53
+ recreate ();
54
+ }
55
+ }
56
+
57
+ @ Override
58
+ protected void onPause () {
59
+ super .onPause ();
60
+ paused = true ;
61
+ }
62
+
47
63
public static int getSelfPort () {
48
64
return selfPort ;
49
65
}
You can’t perform that action at this time.
0 commit comments