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

nx2024
Matthew 4 months ago
parent 6a41210ace
commit 7ff51df1fe

@ -180,25 +180,27 @@ 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();
} }
} }
} }
}; };
long timeout = 500;
if (SystemClock.elapsedRealtime() < 180000) {
// In 3 minutes
timeout = 10000; // in 10 seconds
}
Handler handler = new Handler(); Handler handler = new Handler();
long boottime = SystemClock.elapsedRealtime(); handler.postDelayed(runnable, timeout);
Log.i(TAG, "System boot time =" + boottime ); Log.i(TAG, "Set AutoStart after " + Long.toString(timeout) + "ms");
if(boottime <= 60000)
handler.postDelayed(runnable, 15000);
else
handler.postDelayed(runnable, 500);
} }
} }
@ -238,6 +240,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