Fixed crash when download notification is pressed in landscape mode
authorDavid A. Velasco <dvelasco@solidgear.es>
Wed, 10 Oct 2012 11:45:04 +0000 (13:45 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Wed, 10 Oct 2012 11:45:04 +0000 (13:45 +0200)
src/com/owncloud/android/ui/activity/FileDetailActivity.java

index 539cf26..7937b90 100644 (file)
@@ -52,6 +52,7 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File
     \r
     private boolean mConfigurationChangedToLandscape = false;\r
     private FileDownloaderBinder mDownloaderBinder = null;\r
+    private ServiceConnection mConnection = null;\r
 \r
     @Override\r
     protected void onCreate(Bundle savedInstanceState) {\r
@@ -64,6 +65,7 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File
                                            );\r
 \r
         if (!mConfigurationChangedToLandscape) {\r
+            mConnection = new DetailsServiceConnection();\r
             bindService(new Intent(this, FileDownloader.class), mConnection, Context.BIND_AUTO_CREATE);\r
             \r
             setContentView(R.layout.file_activity_details);\r
@@ -88,14 +90,14 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File
     \r
     \r
     /** Defines callbacks for service binding, passed to bindService() */\r
-    private ServiceConnection mConnection = new ServiceConnection() {\r
+    private class DetailsServiceConnection implements ServiceConnection {\r
 \r
         @Override\r
         public void onServiceConnected(ComponentName className, IBinder service) {\r
             mDownloaderBinder = (FileDownloaderBinder) service;\r
             FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
             if (fragment != null)\r
-                fragment.updateFileDetails();   // a new chance to get the mDownloadBinder through getDownloadBinder()\r
+                fragment.updateFileDetails();   // let the fragment gets the mDownloadBinder through getDownloadBinder() (see FileDetailFragment#updateFileDetais())\r
         }\r
 \r
         @Override\r
@@ -108,7 +110,10 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File
     @Override\r
     public void onDestroy() {\r
         super.onDestroy();\r
-        unbindService(mConnection);\r
+        if (mConnection != null) {\r
+            unbindService(mConnection);\r
+            mConnection = null;\r
+        }\r
     }\r
     \r
     \r