Permalink
Browse files

Finish activity when OperationCanceledException occurs

This will occur when login is cancelled and the activity
cannot load data and so it should gracefully close.

Close issue #15
  • Loading branch information...
1 parent 2714c7b commit 0364c5e744e43449eb766348a6bdfcfa6491f59c @kevinsawicki kevinsawicki committed May 30, 2012
@@ -19,6 +19,8 @@
import static android.content.Intent.ACTION_VIEW;
import static com.github.mobile.gauges.IntentConstants.GAUGE_ID;
import android.accounts.AccountsException;
+import android.accounts.OperationCanceledException;
+import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
@@ -81,6 +83,10 @@ public void onDestroyView() {
} catch (IOException e) {
Log.d(TAG, "Exception getting page content", e);
showError(string.error_loading_contents);
+ } catch (OperationCanceledException e) {
+ Activity activity = getActivity();
+ if (activity != null)
+ activity.finish();
} catch (AccountsException e) {
Log.d(TAG, "Exception getting page content", e);
showError(string.error_loading_contents);
@@ -18,6 +18,7 @@
import static com.github.mobile.gauges.ui.ToastUtil.toastOnUiThread;
import android.accounts.AccountsException;
+import android.accounts.OperationCanceledException;
import android.app.Activity;
import android.util.Log;
import android.widget.Toast;
@@ -71,6 +72,8 @@ protected void showError(final Exception e) {
return serviceProvider.getService().getGauges();
} catch (IOException e) {
showError(e);
+ } catch (OperationCanceledException e) {
+ activity.finish();
} catch (AccountsException e) {
showError(e);
}
@@ -21,6 +21,8 @@
import static com.madgag.android.listviews.ReflectiveHolderFactory.reflectiveFactoryFor;
import static com.madgag.android.listviews.ViewInflator.viewInflatorFor;
import android.accounts.AccountsException;
+import android.accounts.OperationCanceledException;
+import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
@@ -79,6 +81,10 @@ public void onDestroyView() {
} catch (IOException e) {
Log.d(TAG, "Exception getting referrers", e);
showError(string.error_loading_referrers);
+ } catch (OperationCanceledException e) {
+ Activity activity = getActivity();
+ if (activity != null)
+ activity.finish();
} catch (AccountsException e) {
Log.d(TAG, "Exception getting referrers", e);
showError(string.error_loading_referrers);
@@ -89,9 +95,8 @@ public void onDestroyView() {
}
protected ViewHoldingListAdapter<Referrer> adapterFor(List<Referrer> items) {
- return new AlternatingColorListAdapter<Referrer>(getResources(), items, viewInflatorFor(
- getActivity(), layout.referrer_list_item),
- reflectiveFactoryFor(ReferrerViewHolder.class));
+ return new AlternatingColorListAdapter<Referrer>(getResources(), items, viewInflatorFor(getActivity(),
+ layout.referrer_list_item), reflectiveFactoryFor(ReferrerViewHolder.class));
}
public void onListItemClick(ListView l, View v, int position, long id) {
@@ -23,6 +23,8 @@
import static com.madgag.android.listviews.ReflectiveHolderFactory.reflectiveFactoryFor;
import static com.madgag.android.listviews.ViewInflator.viewInflatorFor;
import android.accounts.AccountsException;
+import android.accounts.OperationCanceledException;
+import android.app.Activity;
import android.os.Bundle;
import android.support.v4.content.Loader;
import android.util.Log;
@@ -97,6 +99,10 @@ public void onActivityCreated(Bundle savedInstanceState) {
} catch (IOException e) {
Log.d(TAG, "Exception getting gauge", e);
showError(string.error_loading_traffic);
+ } catch (OperationCanceledException e) {
+ Activity activity = getActivity();
+ if (activity != null)
+ activity.finish();
} catch (AccountsException e) {
Log.d(TAG, "Exception getting gauge", e);
showError(string.error_loading_traffic);

0 comments on commit 0364c5e

Please sign in to comment.