Browse Source

Merge pull request #8630 from nextcloud/fix/8308/dismiss-service-when-in-backgroud

move service dismissal to handler to prevent race-condition
Tobias Kaminsky 3 năm trước cách đây
mục cha
commit
646251c197

+ 9 - 12
src/main/java/com/owncloud/android/files/services/FileDownloader.java

@@ -182,7 +182,6 @@ public class FileDownloader extends Service
         // remove AccountsUpdatedListener
         AccountManager am = AccountManager.get(getApplicationContext());
         am.removeOnAccountsUpdatedListener(this);
-
         super.onDestroy();
     }
 
@@ -423,18 +422,16 @@ public class FileDownloader extends Service
                 }
             }
             mService.mStartedDownload=false;
-            (new Handler()).postDelayed(new Runnable(){
-                public void run() {
-                    if(!mService.mStartedDownload){
-                        mService.mNotificationManager.cancel(R.string.downloader_download_in_progress_ticker);
-                    }
-                }}, 2000);
 
-
-            Log_OC.d(TAG, "Stopping after command with id " + msg.arg1);
-            mService.mNotificationManager.cancel(FOREGROUND_SERVICE_ID);
-            mService.stopForeground(true);
-            mService.stopSelf(msg.arg1);
+            (new Handler()).postDelayed(() -> {
+                if(!mService.mStartedDownload){
+                    mService.mNotificationManager.cancel(R.string.downloader_download_in_progress_ticker);
+                }
+                Log_OC.d(TAG, "Stopping after command with id " + msg.arg1);
+                mService.mNotificationManager.cancel(FOREGROUND_SERVICE_ID);
+                mService.stopForeground(true);
+                mService.stopSelf(msg.arg1);
+            }, 2000);
         }
     }