Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c2f913d0 authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Only update UI when bound

If the PrintActivity gets destroyed (e.g. due to low memory) it gets
re-created when the PrintToPDF activity returns in onActivityResult. In
this case onActivityResult is called right after onCreate and before the
UI is bound. This resulted in a NullPointerException when accessing the
unbound UI elements.

Bug: 21749058
Change-Id: I44e625e8c4f10432591d0afcf7825d7e0dbee6f5
parent 1a8fbfce
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -167,6 +167,8 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat

    public static final PageRange[] ALL_PAGES_ARRAY = new PageRange[]{PageRange.ALL_PAGES};

    private boolean mIsOptionsUiBound = false;

    private final PrinterAvailabilityDetector mPrinterAvailabilityDetector =
            new PrinterAvailabilityDetector();

@@ -1214,6 +1216,9 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
        mPrintButton = (ImageView) findViewById(R.id.print_button);
        mPrintButton.setOnClickListener(clickListener);

        // The UI is now initialized
        mIsOptionsUiBound = true;

        // Special prompt instead of destination spinner for the first time the user printed
        if (!hasUserEverPrinted()) {
            mShowDestinationPrompt = true;
@@ -1390,6 +1395,10 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
    }

    void updateOptionsUi() {
        if (!mIsOptionsUiBound) {
            return;
        }

        // Always update the summary.
        updateSummary();

@@ -1725,6 +1734,10 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
    }

    private void updateSummary() {
        if (!mIsOptionsUiBound) {
            return;
        }

        CharSequence copiesText = null;
        CharSequence mediaSizeText = null;