Performance Considerations
Memory Management:
public class PerformanceOptimizedListener implements AlphynSecurityListener { private final WeakReference<Activity> activityRef;
public PerformanceOptimizedListener(Activity activity) { this.activityRef = new WeakReference<>(activity); }
@Override public void onSuccess(AlphynCallbackResult result) { Activity activity = activityRef.get(); if (activity != null && !activity.isFinishing()) { // Process result only if activity is still valid processResult(result); } }
// Avoid holding strong references to prevent memory leaks private void processResult(AlphynCallbackResult result) { // Efficient result processing if (result.isSecurityScan()) { // Process scan results immediately handleScanResult(result.getScanResult()); } else { // Queue other results for batch processing queueForBatchProcessing(result); } }}Efficient Event Processing:
public class BatchEventProcessor { private final List<AlphynCallbackResult> pendingEvents = new ArrayList<>(); private final Handler batchHandler = new Handler(Looper.getMainLooper()); private static final long BATCH_DELAY_MS = 100;
public void queueEvent(AlphynCallbackResult result) { synchronized (pendingEvents) { pendingEvents.add(result); scheduleBatchProcessing(); } }
private void scheduleBatchProcessing() { batchHandler.removeCallbacks(batchProcessor); batchHandler.postDelayed(batchProcessor, BATCH_DELAY_MS); }
private final Runnable batchProcessor = () -> { synchronized (pendingEvents) { if (!pendingEvents.isEmpty()) { processBatch(new ArrayList<>(pendingEvents)); pendingEvents.clear(); } } };}