cleanup and prevent FC when activity is finishing

This commit is contained in:
ligi 2014-08-24 13:53:04 +02:00
parent bf9ff690a1
commit ae92ec7ce7
2 changed files with 12 additions and 15 deletions

View file

@ -6,11 +6,8 @@ import android.net.Uri;
class ExportProblemPassToLigiAndFinishTask extends PassExportTask { class ExportProblemPassToLigiAndFinishTask extends PassExportTask {
private final Activity activity;
public ExportProblemPassToLigiAndFinishTask(Activity activity, String path, String zip_path, String zip_fname) { public ExportProblemPassToLigiAndFinishTask(Activity activity, String path, String zip_path, String zip_fname) {
super(activity, path, zip_path, zip_fname, false); super(activity, path, zip_path, zip_fname, false);
this.activity = activity;
} }
@Override @Override
@ -25,7 +22,7 @@ class ExportProblemPassToLigiAndFinishTask extends PassExportTask {
it.setType("text/plain"); it.setType("text/plain");
it.putExtra(Intent.EXTRA_TEXT, ""); it.putExtra(Intent.EXTRA_TEXT, "");
ctx.startActivity(Intent.createChooser(it, "How to send Pass?")); activity.startActivity(Intent.createChooser(it, "How to send Pass?"));
activity.finish(); activity.finish();

View file

@ -1,7 +1,7 @@
package org.ligi.passandroid.ui; package org.ligi.passandroid.ui;
import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
@ -20,32 +20,32 @@ import java.util.zip.ZipOutputStream;
class PassExportTask extends AsyncTask<Void, Void, Void> { class PassExportTask extends AsyncTask<Void, Void, Void> {
private final ProgressDialog progress_dialog; private final ProgressDialog progress_dialog;
protected final Context ctx; protected final Activity activity;
private final String inputPath; private final String inputPath;
protected final String zipFileName, zipPath; protected final String zipFileName, zipPath;
private boolean share_after_export; private boolean share_after_export;
private Exception exception; private Exception exception;
public PassExportTask(final Context ctx, public PassExportTask(final Activity activity,
final String inputPath, final String inputPath,
final String zipPath, final String zipPath,
final String zipFileName, final String zipFileName,
final boolean share_after_export) { final boolean share_after_export) {
super(); super();
this.ctx = ctx; this.activity = activity;
this.inputPath = inputPath; this.inputPath = inputPath;
this.zipFileName = zipFileName; this.zipFileName = zipFileName;
this.zipPath = zipPath; this.zipPath = zipPath;
this.share_after_export = share_after_export; this.share_after_export = share_after_export;
progress_dialog = new ProgressDialog(ctx); progress_dialog = new ProgressDialog(activity);
} }
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
progress_dialog.setTitle(ctx.getString(R.string.preparing_pass)); progress_dialog.setTitle(activity.getString(R.string.preparing_pass));
progress_dialog.setMessage(ctx.getString(R.string.please_wait)); progress_dialog.setMessage(activity.getString(R.string.please_wait));
progress_dialog.show(); progress_dialog.show();
super.onPreExecute(); super.onPreExecute();
} }
@ -97,21 +97,21 @@ class PassExportTask extends AsyncTask<Void, Void, Void> {
protected void onPostExecute(Void aVoid) { protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid); super.onPostExecute(aVoid);
if (progress_dialog.isShowing()) { if (!activity.isFinishing() && progress_dialog.isShowing()) {
progress_dialog.dismiss(); progress_dialog.dismiss();
} }
if (exception != null) { if (exception != null) {
Toast.makeText(ctx, "could not export pass " + exception, Toast.LENGTH_LONG).show(); Toast.makeText(activity, "could not export pass " + exception, Toast.LENGTH_LONG).show();
return; return;
} }
if (share_after_export) { if (share_after_export) {
Intent it = new Intent(Intent.ACTION_SEND); Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, ctx.getString(R.string.passbook_is_shared_subject)); it.putExtra(Intent.EXTRA_SUBJECT, activity.getString(R.string.passbook_is_shared_subject));
it.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + zipPath + zipFileName)); it.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + zipPath + zipFileName));
it.setType("application/vnd.apple.pkpass"); it.setType("application/vnd.apple.pkpass");
ctx.startActivity(Intent.createChooser(it, ctx.getString(R.string.passbook_share_chooser_title))); activity.startActivity(Intent.createChooser(it, activity.getString(R.string.passbook_share_chooser_title)));
} }
} }