@@ -80,21 +80,15 @@ protected void onCreate(Bundle savedInstanceState) {
80
80
Log .e (TAG , "Activity returned NULL uri" );
81
81
return ;
82
82
}
83
- // Running this in a thread prevents Android from throwing a NetworkOnMainThreadException for large files
84
- // FIXME: This is still suboptimal, because showing that the export started is delayed until the network request finishes
85
- new Thread () {
86
- @ Override
87
- public void run () {
88
- try {
89
- OutputStream writer = getContentResolver ().openOutputStream (uri );
90
- Log .d (TAG , "Starting file export with: " + result );
91
- startExport (writer , uri , exportPassword .toCharArray (), true );
92
- } catch (IOException e ) {
93
- Log .e (TAG , "Failed to export file: " + result , e );
94
- onExportComplete (new ImportExportResult (ImportExportResultType .GenericFailure , result .toString ()), uri );
95
- }
96
- }
97
- }.start ();
83
+ try {
84
+ OutputStream writer = getContentResolver ().openOutputStream (uri );
85
+ Log .e (TAG , "Starting file export with: " + result .toString ());
86
+ startExport (writer , uri , exportPassword .toCharArray (), true );
87
+ } catch (IOException e ) {
88
+ Log .e (TAG , "Failed to export file: " + result .toString (), e );
89
+ onExportComplete (new ImportExportResult (ImportExportResultType .GenericFailure , result .toString ()), uri );
90
+ }
91
+
98
92
});
99
93
fileOpenLauncher = registerForActivityResult (new ActivityResultContracts .GetContent (), result -> {
100
94
if (result == null ) {
@@ -166,21 +160,14 @@ public void run() {
166
160
}
167
161
168
162
private void openFileForImport (Uri uri , char [] password ) {
169
- // Running this in a thread prevents Android from throwing a NetworkOnMainThreadException for large files
170
- // FIXME: This is still suboptimal, because showing that the import started is delayed until the network request finishes
171
- new Thread () {
172
- @ Override
173
- public void run () {
174
- try {
175
- InputStream reader = getContentResolver ().openInputStream (uri );
176
- Log .d (TAG , "Starting file import with: " + uri );
177
- startImport (reader , uri , importDataFormat , password , true );
178
- } catch (IOException e ) {
179
- Log .e (TAG , "Failed to import file: " + uri , e );
180
- onImportComplete (new ImportExportResult (ImportExportResultType .GenericFailure , e .toString ()), uri , importDataFormat );
181
- }
182
- }
183
- }.start ();
163
+ try {
164
+ InputStream reader = getContentResolver ().openInputStream (uri );
165
+ Log .e (TAG , "Starting file import with: " + uri .toString ());
166
+ startImport (reader , uri , importDataFormat , password , true );
167
+ } catch (IOException e ) {
168
+ Log .e (TAG , "Failed to import file: " + uri .toString (), e );
169
+ onImportComplete (new ImportExportResult (ImportExportResultType .GenericFailure , e .toString ()), uri , importDataFormat );
170
+ }
184
171
}
185
172
186
173
private void chooseImportType (boolean choosePicker ,
0 commit comments