Merge "Handle more config changes and handle onDestroy" into nyc-dev

This commit is contained in:
Philip P. Moltmann
2016-05-02 16:43:50 +00:00
committed by Android (Google) Code Review
3 changed files with 28 additions and 9 deletions

View File

@@ -57,7 +57,7 @@
<activity <activity
android:name=".ui.PrintActivity" android:name=".ui.PrintActivity"
android:configChanges="screenSize|smallestScreenSize|orientation|locale|keyboard|keyboardHidden|fontScale|uiMode|layoutDirection" android:configChanges="mnc|mnc|touchscreen|navigation|screenLayout|screenSize|smallestScreenSize|orientation|locale|keyboard|keyboardHidden|fontScale|uiMode|layoutDirection|density"
android:permission="android.permission.BIND_PRINT_SPOOLER_SERVICE" android:permission="android.permission.BIND_PRINT_SPOOLER_SERVICE"
android:theme="@style/Theme.PrintActivity"> android:theme="@style/Theme.PrintActivity">
<intent-filter> <intent-filter>

View File

@@ -510,7 +510,12 @@ public final class PageContentRepository {
public void destroy() { public void destroy() {
if (mBoundToService) { if (mBoundToService) {
mBoundToService = false; mBoundToService = false;
mContext.unbindService(AsyncRenderer.this); try {
mContext.unbindService(AsyncRenderer.this);
} catch (IllegalArgumentException e) {
// Service might have been forcefully unbound in onDestroy()
Log.e(LOG_TAG, "Cannot unbind service", e);
}
} }
mPageContentCache.invalidate(); mPageContentCache.invalidate();

View File

@@ -268,7 +268,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
if (isFinishing()) { if (isFinishing() || isDestroyed()) {
// onPause might have not been able to cancel the job, see PrintActivity#onPause // onPause might have not been able to cancel the job, see PrintActivity#onPause
// To be sure, cancel the job again. Double canceling does no harm. // To be sure, cancel the job again. Double canceling does no harm.
mSpoolerProvider.getSpooler().setPrintJobState(mPrintJob.getId(), mSpoolerProvider.getSpooler().setPrintJobState(mPrintJob.getId(),
@@ -320,7 +320,8 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
// If we are finishing or we are in a state that we do not need any // If we are finishing or we are in a state that we do not need any
// data from the printing app, then no need to finish. // data from the printing app, then no need to finish.
if (isFinishing() || (isFinalState(mState) && !mPrintedDocument.isUpdating())) { if (isFinishing() || isDestroyed() ||
(isFinalState(mState) && !mPrintedDocument.isUpdating())) {
return; return;
} }
setState(STATE_PRINT_CANCELED); setState(STATE_PRINT_CANCELED);
@@ -617,6 +618,17 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
} }
} }
@Override
protected void onDestroy() {
if (mPrintedDocument != null) {
mPrintedDocument.cancel(true);
}
doFinish();
super.onDestroy();
}
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) { switch (requestCode) {
@@ -960,7 +972,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
} }
private void ensureProgressUiShown() { private void ensureProgressUiShown() {
if (isFinishing()) { if (isFinishing() || isDestroyed()) {
return; return;
} }
if (mUiState != UI_STATE_PROGRESS) { if (mUiState != UI_STATE_PROGRESS) {
@@ -972,7 +984,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
} }
private void ensurePreviewUiShown() { private void ensurePreviewUiShown() {
if (isFinishing()) { if (isFinishing() || isDestroyed()) {
return; return;
} }
if (mUiState != UI_STATE_PREVIEW) { if (mUiState != UI_STATE_PREVIEW) {
@@ -983,7 +995,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
} }
private void ensureErrorUiShown(CharSequence message, int action) { private void ensureErrorUiShown(CharSequence message, int action) {
if (isFinishing()) { if (isFinishing() || isDestroyed()) {
return; return;
} }
if (mUiState != UI_STATE_ERROR) { if (mUiState != UI_STATE_ERROR) {
@@ -1350,7 +1362,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
@Override @Override
public void onLoaderReset(Loader<List<PrintServiceInfo>> loader) { public void onLoaderReset(Loader<List<PrintServiceInfo>> loader) {
if (!isFinishing()) { if (!(isFinishing() || isDestroyed())) {
onLoadFinished(loader, null); onLoadFinished(loader, null);
} }
} }
@@ -2033,7 +2045,9 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
mSpoolerProvider.destroy(); mSpoolerProvider.destroy();
} }
setState(mProgressMessageController.cancel()); if (mProgressMessageController != null) {
setState(mProgressMessageController.cancel());
}
if (mState != STATE_INITIALIZING) { if (mState != STATE_INITIALIZING) {
mPrintedDocument.finish(); mPrintedDocument.finish();