Fixed crash due to lifecycle of registered SyncBroadcastReceiver

This commit is contained in:
David A. Velasco 2016-03-04 11:46:12 +01:00
parent 3ce879be24
commit 5707fce666

View file

@ -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 {