Skip to content

Commit

Permalink
improve lifecyle of clients
Browse files Browse the repository at this point in the history
  • Loading branch information
jpihl committed Dec 13, 2017
1 parent c34f643 commit f3620c7
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 24 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
google()
jcenter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
protected void onStart() {
super.onStart();
if (keepAlive != null)
keepAlive.start();
}

@Override
protected void onResume() {
super.onResume();
startStopToggleButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
buttonView.setEnabled(false);

Expand All @@ -93,18 +100,24 @@ protected void onStart() {
lookingForSeverLinearLayout.setVisibility(View.VISIBLE);
}
});
if (keepAlive != null)
keepAlive.start();
}

@Override
protected void onStop() {
super.onStop();
client.stop();
if (keepAlive != null)
keepAlive.stop();
}

@Override
protected void onDestroy() {
super.onDestroy();
if (isFinishing()) {
client.stop();
backgroundHandler.stop();
}
}

private class ClientOnEventListener implements Client.OnEventListener {
@Override
public void onError(String reason) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
protected void onStart() {
super.onStart();
if (keepAlive != null)
keepAlive.start();
}

@Override
protected void onResume() {
super.onResume();
startStopToggleButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
buttonView.setEnabled(false);

Expand All @@ -143,18 +150,25 @@ protected void onStart() {
lookingForSeverLinearLayout.setVisibility(View.VISIBLE);
}
});
if (keepAlive != null)
keepAlive.start();
}

@Override
protected void onStop() {
super.onStop();
client.stop();
if (keepAlive != null)
keepAlive.stop();
}


@Override
protected void onDestroy() {
super.onDestroy();
if (isFinishing()) {
client.stop();
backgroundHandler.stop();
}
}

/**
* Hides the UI of the application
*/
Expand Down
2 changes: 1 addition & 1 deletion client/src/main/res/values-v21/booleans.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="sdk_version_16_available">true</bool>
</resources>
</resources>
2 changes: 1 addition & 1 deletion client/src/main/res/values/booleans.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="sdk_version_16_available">false</bool>
</resources>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;
import android.widget.ToggleButton;

import com.steinwurf.score.server_reference.R;
Expand Down Expand Up @@ -80,12 +79,6 @@ public class CameraActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Toast.makeText(this, "This application requires SDK level 21", Toast.LENGTH_SHORT).show();
finish();
return;
}

setContentView(R.layout.activity_main);
startStopToggleButton = findViewById(R.id.startStopToggleButton);
backgroundHandler.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ public class ScreenCaptureActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Toast.makeText(this, "This application requires SDK level 21", Toast.LENGTH_SHORT).show();
finish();
return;
}

setContentView(R.layout.activity_main);

startStopToggleButton = findViewById(R.id.startStopToggleButton);
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/res/values-v21/booleans.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="sdk_version_21_available">true</bool>
</resources>
</resources>
2 changes: 1 addition & 1 deletion server/src/main/res/values/booleans.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="sdk_version_21_available">false</bool>
</resources>
</resources>

0 comments on commit f3620c7

Please sign in to comment.