use try-with-resources

This commit is contained in:
Unpublished
2019-02-22 16:59:23 +01:00
parent 72dcc50ea1
commit 0edc7a8629
16 changed files with 117 additions and 316 deletions

View File

@@ -296,23 +296,18 @@ public class FragmentRule extends FragmentBase {
}
private void handlePickContact(Intent data) {
Cursor cursor = null;
try {
Uri uri = data.getData();
if (uri != null)
cursor = getContext().getContentResolver().query(uri,
new String[]{
ContactsContract.CommonDataKinds.Email.ADDRESS
},
null, null, null);
Uri uri = data.getData();
if (uri == null) return;
try (Cursor cursor = getContext().getContentResolver().query(uri,
new String[]{
ContactsContract.CommonDataKinds.Email.ADDRESS
},
null, null, null)) {
if (cursor != null && cursor.moveToFirst())
etSender.setText(cursor.getString(0));
} catch (Throwable ex) {
Log.e(ex);
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
} finally {
if (cursor != null)
cursor.close();
}
}