Fixes for a couple of strict mode violations.
- Removing from call log and trashing voicemails were both operating on
ui thread.
- Decision here is not to finish until after the post execute completes.
- I could go further and test the result of the delete, and show a toast
if the delete doesn't work, but for now leaving that work for later.
Bug: 5113695
Bug: 5098527
Change-Id: I5937de2e5c3da3794439f3fa510276b799162b0d
diff --git a/src/com/android/contacts/CallDetailActivity.java b/src/com/android/contacts/CallDetailActivity.java
index d093453..dd71a90 100644
--- a/src/com/android/contacts/CallDetailActivity.java
+++ b/src/com/android/contacts/CallDetailActivity.java
@@ -33,6 +33,7 @@
import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.CallLog;
import android.provider.CallLog.Calls;
@@ -641,20 +642,21 @@
}
public void onMenuRemoveFromCallLog(MenuItem menuItem) {
- StringBuilder callIds = new StringBuilder();
+ final StringBuilder callIds = new StringBuilder();
for (Uri callUri : getCallLogEntryUris()) {
if (callIds.length() != 0) {
callIds.append(",");
}
callIds.append(ContentUris.parseId(callUri));
}
-
- getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL,
- Calls._ID + " IN (" + callIds + ")", null);
- // Also close the activity.
- finish();
+ runInBackgroundThenFinishActivity(new Runnable() {
+ @Override
+ public void run() {
+ getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL,
+ Calls._ID + " IN (" + callIds + ")", null);
+ }
+ });
}
-
public void onMenuEditNumberBeforeCall(MenuItem menuItem) {
startActivity(new Intent(Intent.ACTION_DIAL, mPhoneNumberHelper.getCallUri(mNumber)));
}
@@ -664,8 +666,30 @@
}
public void onMenuTrashVoicemail(MenuItem menuItem) {
- getContentResolver().delete(getVoicemailUri(), null, null);
- finish();
+ final Uri voicemailUri = getVoicemailUri();
+ runInBackgroundThenFinishActivity(new Runnable() {
+ @Override
+ public void run() {
+ getContentResolver().delete(voicemailUri, null, null);
+ }
+ });
+ }
+
+ /**
+ * Run a task in the background, and then finish this activity when the task is done.
+ */
+ private void runInBackgroundThenFinishActivity(final Runnable runnable) {
+ new AsyncTask<Void, Void, Void>() {
+ @Override
+ protected Void doInBackground(Void... params) {
+ runnable.run();
+ return null;
+ }
+ @Override
+ protected void onPostExecute(Void result) {
+ finish();
+ }
+ }.execute();
}
private void configureActionBar() {