Added delay to allow activity to bind to server before trying to access server variables.

This commit is contained in:
Graham Jones
2022-01-10 20:29:36 +00:00
parent 783abd93f0
commit dc5719c64c
2 changed files with 30 additions and 2 deletions

View File

@@ -40,7 +40,6 @@ public class LogManagerControlActivity extends AppCompatActivity {
mContext = this; mContext = this;
mUtil = new OsdUtil(this, serverStatusHandler); mUtil = new OsdUtil(this, serverStatusHandler);
mConnection = new SdServiceConnection(this); mConnection = new SdServiceConnection(this);
mUtil.bindToServer(this, mConnection);
setContentView(R.layout.activity_log_manager_control); setContentView(R.layout.activity_log_manager_control);
@@ -65,17 +64,20 @@ public class LogManagerControlActivity extends AppCompatActivity {
protected void onStart() { protected void onStart() {
Log.v(TAG, "onStart()"); Log.v(TAG, "onStart()");
super.onStart(); super.onStart();
mUtil.bindToServer(this, mConnection);
//startUiTimer(); //startUiTimer();
} }
@Override @Override
protected void onStop() { protected void onStop() {
Log.v(TAG,"onStop()");
super.onStop(); super.onStop();
mUtil.unbindFromServer(this, mConnection); mUtil.unbindFromServer(this, mConnection);
} }
@Override @Override
protected void onPause() { protected void onPause() {
Log.v(TAG,"onPause()");
super.onPause(); super.onPause();
stopUiTimer(); stopUiTimer();
} }

View File

@@ -37,6 +37,10 @@ public class ReportSeizureActivity extends AppCompatActivity {
private int mYear, mMonth, mDay, mHour, mMinute; private int mYear, mMonth, mDay, mHour, mMinute;
private String mMsg = "Messages"; private String mMsg = "Messages";
private OsdUtil osdUtil; private OsdUtil osdUtil;
private SdServiceConnection mConnection;
private OsdUtil mUtil;
final Handler serverStatusHandler = new Handler();
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -46,7 +50,21 @@ public class ReportSeizureActivity extends AppCompatActivity {
Handler h = new Handler(); Handler h = new Handler();
osdUtil = new OsdUtil(mContext, h); osdUtil = new OsdUtil(mContext, h);
setContentView(R.layout.activity_report_seizure); setContentView(R.layout.activity_report_seizure);
mLm= new LogManager(mContext); mUtil = new OsdUtil(this, serverStatusHandler);
mConnection = new SdServiceConnection(this);
// It takes a finite time for
// the mConnection to bind to the service, so we delay half a second to give it chance
// to connect before trying to get the SdServer LogManager instance)
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Log.v(TAG,"onCreate(): setting mLm");
mLm = mConnection.mSdServer.mLm;
}
}, 100);
//mLm= new LogManager(mContext);
Button okBtn = Button okBtn =
(Button) findViewById(R.id.OKBtn); (Button) findViewById(R.id.OKBtn);
@@ -79,6 +97,7 @@ public class ReportSeizureActivity extends AppCompatActivity {
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
mUtil.bindToServer(this, mConnection);
//startUiTimer(); //startUiTimer();
} }
@@ -94,6 +113,13 @@ public class ReportSeizureActivity extends AppCompatActivity {
startUiTimer(); startUiTimer();
} }
@Override
protected void onStop() {
super.onStop();
mUtil.unbindFromServer(this, mConnection);
}
private void updateUi() { private void updateUi() {
//Log.v(TAG,"updateUi()"); //Log.v(TAG,"updateUi()");
TextView tv; TextView tv;