android: Avoid IllegalStateException when importing certificates

When certificates are imported via Storage Access Framework we did handle
the selection directly in onActivityResult().  However, at that point the
activity might apparently not yet be resumed.  So committing
FragmentTransactions could result in IllegalStateExceptions due to the
potential state loss.  To avoid that we cache the returned URI and wait
until onPostResume() to make sure the activity's state is fully restored
before showing the confirmation dialog.
This commit is contained in:
Tobias Brunner
2016-05-06 12:51:49 +02:00
parent b9522f9d64
commit 1130dbc408
@@ -52,6 +52,7 @@ public class TrustedCertificateImportActivity extends AppCompatActivity
"application/x-pem-file",
"application/pkix-cert"
};
private Uri mCertificateUri;
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
@@ -82,18 +83,29 @@ public class TrustedCertificateImportActivity extends AppCompatActivity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode)
{
case OPEN_DOCUMENT:
if (resultCode == Activity.RESULT_OK && data != null)
{
importCertificate(data.getData());
mCertificateUri = data.getData();
return;
}
finish();
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onPostResume()
{
super.onPostResume();
if (mCertificateUri != null)
{
importCertificate(mCertificateUri);
mCertificateUri = null;
}
}
/**