| Index: platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java
|
| diff --git a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java
|
| index 4b890bd5e1279cb2437a205d581b54aa04dffabc..ee1695afd1e9cd60fe25a0d44bd8a1ef271a023e 100644
|
| --- a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java
|
| +++ b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java
|
| @@ -12,6 +12,7 @@ import android.app.Application;
|
| public class ViewerApplication extends Application {
|
| private long mNativeHandle = 0;
|
| private ViewerActivity mViewerActivity;
|
| + private String mStateJsonStr, mTitle;
|
|
|
| static {
|
| System.loadLibrary("skia_android");
|
| @@ -41,16 +42,40 @@ public class ViewerApplication extends Application {
|
| }
|
|
|
| public void setViewerActivity(ViewerActivity viewerActivity) {
|
| - this.mViewerActivity = viewerActivity;
|
| + mViewerActivity = viewerActivity;
|
| + // Note that viewerActivity might be null (called by onDestroy)
|
| + if (mViewerActivity != null) {
|
| + // A new ViewerActivity is created; initialize its state and title
|
| + if (mStateJsonStr != null) {
|
| + mViewerActivity.setState(mStateJsonStr);
|
| + }
|
| + if (mTitle != null) {
|
| + mViewerActivity.setTitle(mTitle);
|
| + }
|
| + }
|
| }
|
|
|
| public void setTitle(String title) {
|
| - final String finalTitle = title;
|
| + mTitle = title; // Similar to mStateJsonStr, we have to store this.
|
| + if (mViewerActivity != null) {
|
| + mViewerActivity.runOnUiThread(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + mViewerActivity.setTitle(mTitle);
|
| + }
|
| + });
|
| + }
|
| + }
|
| +
|
| + public void setState(String stateJsonStr) {
|
| + // We have to store this state because ViewerActivity may be destroyed while the native app
|
| + // is still running. When a new ViewerActivity is created, we'll pass the state to it.
|
| + mStateJsonStr = stateJsonStr;
|
| if (mViewerActivity != null) {
|
| mViewerActivity.runOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| - mViewerActivity.setTitle(finalTitle);
|
| + mViewerActivity.setState(mStateJsonStr);
|
| }
|
| });
|
| }
|
|
|