Skip to content

Commit

Permalink
Periodic UI updates on BluetoothActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
platypii committed Nov 13, 2024
1 parent db44a53 commit 3100506
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.platypii.baseline.views.bluetooth;

import android.os.Handler;
import androidx.annotation.NonNull;
import com.platypii.baseline.Intents;
import com.platypii.baseline.R;
Expand All @@ -24,6 +25,16 @@ public class BluetoothActivity extends BaseActivity implements Subscriber<MLocat

private ActivityBluetoothBinding binding;

// Periodic UI updates
private static final int signalUpdateInterval = 200; // milliseconds
private final Handler handler = new Handler();
private final Runnable signalRunnable = new Runnable() {
public void run() {
updateViews();
handler.postDelayed(this, signalUpdateInterval);
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -125,13 +136,16 @@ public void onResume() {
EventBus.getDefault().register(this);
Services.location.locationUpdates.subscribeMain(this);
updateViews();
// Start regular ui updates
handler.post(signalRunnable);
}

@Override
public void onPause() {
super.onPause();
EventBus.getDefault().unregister(this);
Services.location.locationUpdates.unsubscribeMain(this);
handler.removeCallbacks(signalRunnable);
}

@Subscribe(threadMode = ThreadMode.MAIN)
Expand Down

0 comments on commit 3100506

Please sign in to comment.