Skip to content

Commit c0e5a39

Browse files
committed
Attepted fix of NPE in #1783
1 parent 7551226 commit c0e5a39

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

  • android/sdl_android/src/main/java/com/smartdevicelink/managers

android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ public class SdlManager extends BaseSdlManager {
9191
private VideoStreamManager videoStreamManager;
9292
private AudioStreamManager audioStreamManager;
9393

94+
private Handler handler = new Handler(Looper.getMainLooper());
95+
private Runnable changeRegistrationRunnable = new Runnable() {
96+
@Override
97+
public void run() {
98+
checkLifecycleConfiguration();
99+
DebugTool.logInfo(TAG, "Retry Change Registration Count: " + changeRegistrationRetry);
100+
}
101+
};
102+
103+
94104
/**
95105
* Starts up a SdlManager, and calls provided callback called once all BaseSubManagers are done setting up
96106
*/
@@ -211,14 +221,9 @@ private void notifyDevListener(String info) {
211221
void retryChangeRegistration() {
212222
changeRegistrationRetry++;
213223
if (changeRegistrationRetry < MAX_RETRY) {
214-
final Handler handler = new Handler(Looper.getMainLooper());
215-
handler.postDelayed(new Runnable() {
216-
@Override
217-
public void run() {
218-
checkLifecycleConfiguration();
219-
DebugTool.logInfo(TAG, "Retry Change Registration Count: " + changeRegistrationRetry);
220-
}
221-
}, 3000);
224+
if (handler != null && changeRegistrationRunnable != null) {
225+
handler.postDelayed(changeRegistrationRunnable, 3000);
226+
}
222227
}
223228
}
224229

@@ -258,6 +263,15 @@ public synchronized void dispose() {
258263
this.lifecycleManager.stop();
259264
}
260265

266+
if (handler != null) {
267+
if (changeRegistrationRunnable != null) {
268+
handler.removeCallbacks(changeRegistrationRunnable);
269+
changeRegistrationRunnable = null;
270+
}
271+
272+
handler = null;
273+
}
274+
261275
if (managerListener != null) {
262276
managerListener.onDestroy();
263277
managerListener = null;

0 commit comments

Comments
 (0)