From 5707fce6662be197bae23e8f843e787f8be7711e Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Fri, 4 Mar 2016 11:46:12 +0100 Subject: [PATCH] Fixed crash due to lifecycle of registered SyncBroadcastReceiver --- .../android/ui/activity/Uploader.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/com/owncloud/android/ui/activity/Uploader.java b/src/com/owncloud/android/ui/activity/Uploader.java index a182c337ce..c0574ebf79 100644 --- a/src/com/owncloud/android/ui/activity/Uploader.java +++ b/src/com/owncloud/android/ui/activity/Uploader.java @@ -179,6 +179,13 @@ public class Uploader extends FileActivity if (mAccountSelected) { setAccount((Account) savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT)); } + + // Listen for sync messages + IntentFilter syncIntentFilter = new IntentFilter(RefreshFolderOperation. + EVENT_SINGLE_FOLDER_CONTENTS_SYNCED); + syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED); + mSyncBroadcastReceiver = new SyncBroadcastReceiver(); + registerReceiver(mSyncBroadcastReceiver, syncIntentFilter); } @Override @@ -203,13 +210,6 @@ public class Uploader extends FileActivity showDialog(DIALOG_NO_STREAM); } - // Listen for sync messages - IntentFilter syncIntentFilter = new IntentFilter(RefreshFolderOperation. - EVENT_SINGLE_FOLDER_CONTENTS_SYNCED); - syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED); - mSyncBroadcastReceiver = new SyncBroadcastReceiver(); - registerReceiver(mSyncBroadcastReceiver, syncIntentFilter); - super.setAccount(account, savedAccount); } @@ -236,6 +236,14 @@ public class Uploader extends FileActivity Log_OC.d(TAG, "onSaveInstanceState() end"); } + @Override + protected void onDestroy(){ + if (mSyncBroadcastReceiver != null) { + unregisterReceiver(mSyncBroadcastReceiver); + } + super.onDestroy(); + } + @Override protected Dialog onCreateDialog(final int id) { final AlertDialog.Builder builder = new Builder(this); @@ -357,7 +365,6 @@ public class Uploader extends FileActivity @Override public void onBackPressed() { if (mParents.size() <= 1) { - unregisterReceiver(mSyncBroadcastReceiver); super.onBackPressed(); return; } else {