减小系统重启后第一次启动的延迟,避免运维重启mpapp

ptz
Matthew 4 months ago
parent 8a14578952
commit 04b8ce7796

@ -174,12 +174,13 @@ public class MainActivity extends AppCompatActivity {
} }
if (MicroPhotoContext.hasMpAppConfig(appContext)) { if (MicroPhotoContext.hasMpAppConfig(appContext)) {
Runnable runnable = new Runnable() { final Runnable runnable = new Runnable() {
@Override @Override
public void run() { public void run() {
if (!MicroPhotoService.isRunning && !TextUtils.isEmpty(appConfig.cmdid) && !TextUtils.isEmpty(appConfig.server) && appConfig.port != 0) { if (!MicroPhotoService.isRunning && !TextUtils.isEmpty(appConfig.cmdid) && !TextUtils.isEmpty(appConfig.server) && appConfig.port != 0) {
if (binding.btnStartServ.isEnabled()) { if (binding.btnStartServ.isEnabled()) {
Log.i(TAG, "Perform AutoStart");
binding.btnStartServ.performClick(); binding.btnStartServ.performClick();
} }
} }
@ -189,10 +190,11 @@ public class MainActivity extends AppCompatActivity {
long timeout = 500; long timeout = 500;
if (SystemClock.elapsedRealtime() < 180000) { if (SystemClock.elapsedRealtime() < 180000) {
// In 3 minutes // In 3 minutes
timeout = 30000; // in 30 seconds timeout = 10000; // in 10 seconds
} }
Handler handler = new Handler(); Handler handler = new Handler();
handler.postDelayed(runnable, timeout); handler.postDelayed(runnable, timeout);
Log.i(TAG, "Set AutoStart after " + Long.toString(timeout) + "ms");
} }
} }
@ -232,6 +234,7 @@ public class MainActivity extends AppCompatActivity {
startMicroPhotoService(appContext, curAppConfig, mMessenger); startMicroPhotoService(appContext, curAppConfig, mMessenger);
Log.i(TAG, "Service auto-started");
binding.btnStartServ.setEnabled(false); binding.btnStartServ.setEnabled(false);
binding.btnStopServ.setEnabled(true); binding.btnStopServ.setEnabled(true);
} }

Loading…
Cancel
Save