Skip to content

Commit fa1ee68

Browse files
androi: Fixed crash when trying to open InAppBrowser with R.menu.menu_main on release mode, updated android activities restore from savedInstanceState
1 parent 60d2562 commit fa1ee68

File tree

7 files changed

+53
-27
lines changed

7 files changed

+53
-27
lines changed

flutter_inappwebview/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
- Added `CookieManager.flush` method
1818
- Updated `InAppWebViewController.takeScreenshot` implementation to support screenshot out of visible viewport when `InAppWebViewController.enableSlowWholeDocumentDraw` is called
1919
- Fixed "After dispose a InAppWebViewKeepAlive using InAppWebViewController.disposeKeepAlive. NullPointerException is thrown when main activity enter destroyed state." [#2025](https://github.com/pichillilorenzo/flutter_inappwebview/issues/2025)
20+
- Fixed crash when trying to open InAppBrowser with R.menu.menu_main on release mode
21+
- Merged "Prevent blank InAppBrowser Activity from being restored" [#1984](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1984) (thanks to [ShuheiSuzuki-07](https://github.com/ShuheiSuzuki-07))
2022

2123
#### macOS and iOS Platforms
2224
- Moved `WKUserContentController` initialization on `preWKWebViewConfiguration` to fix possible `undefined is not an object (evaluating 'window.webkit.messageHandlers')` javascript error

flutter_inappwebview/example/android/app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ android {
4545

4646
buildTypes {
4747
release {
48+
// only for com.pichillilorenzo.flutter_inappwebview_android.R.menu.menu_main
49+
minifyEnabled false
50+
shrinkResources false
51+
4852
// TODO: Add your own signing config for the release build.
4953
// Signing with the debug keys for now, so `flutter run --release` works.
5054
signingConfig signingConfigs.debug

flutter_inappwebview/example/lib/main.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ Future main() async {
2222
// await Permission.microphone.request();
2323
// await Permission.storage.request();
2424

25-
await localhostServer.start();
26-
2725
if (!kIsWeb && defaultTargetPlatform == TargetPlatform.windows) {
2826
final availableVersion = await WebViewEnvironment.getAvailableVersion();
2927
assert(availableVersion != null,

flutter_inappwebview/pubspec.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ dependencies:
2121
flutter:
2222
sdk: flutter
2323
flutter_inappwebview_platform_interface: ^1.4.0
24-
flutter_inappwebview_android: ^1.1.3
25-
flutter_inappwebview_ios: ^1.1.2
26-
flutter_inappwebview_macos: ^1.1.2
27-
flutter_inappwebview_web: ^1.1.2
28-
flutter_inappwebview_windows: ^0.6.0
24+
flutter_inappwebview_android: ^1.2.0
25+
flutter_inappwebview_ios: ^1.2.0
26+
flutter_inappwebview_macos: ^1.2.0
27+
flutter_inappwebview_web: ^1.2.0
28+
flutter_inappwebview_windows: ^0.7.0
2929

3030
dev_dependencies:
3131
flutter_test:

flutter_inappwebview_android/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- Added `CookieManager.flush` method
66
- Updated `InAppWebViewController.takeScreenshot` implementation to support screenshot out of visible viewport when `InAppWebViewController.enableSlowWholeDocumentDraw` is called
77
- Fixed "After dispose a InAppWebViewKeepAlive using InAppWebViewController.disposeKeepAlive. NullPointerException is thrown when main activity enter destroyed state." [#2025](https://github.com/pichillilorenzo/flutter_inappwebview/issues/2025)
8+
- Fixed crash when trying to open InAppBrowser with R.menu.menu_main on release mode
9+
- Merged "Prevent blank InAppBrowser Activity from being restored" [#1984](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1984) (thanks to [ShuheiSuzuki-07](https://github.com/ShuheiSuzuki-07))
810

911
## 1.1.3
1012

flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/chrome_custom_tabs/ChromeCustomTabsActivity.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,23 @@ protected void onCreate(Bundle savedInstanceState) {
7878
setContentView(R.layout.chrome_custom_tabs_layout);
7979

8080
Bundle b = getIntent().getExtras();
81-
if (b == null) return;
81+
if (b == null) {
82+
if (savedInstanceState != null) {
83+
close();
84+
}
85+
return;
86+
}
8287

8388
id = b.getString("id");
8489

8590
String managerId = b.getString("managerId");
8691
manager = ChromeSafariBrowserManager.shared.get(managerId);
87-
if (manager == null || manager.plugin == null || manager.plugin.messenger == null) return;
92+
if (manager == null || manager.plugin == null || manager.plugin.messenger == null) {
93+
if (savedInstanceState != null) {
94+
close();
95+
}
96+
return;
97+
}
8898

8999
manager.browsers.put(id, this);
90100

flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/in_app_browser/InAppBrowserActivity.java

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
public class InAppBrowserActivity extends AppCompatActivity implements InAppBrowserDelegate, Disposable {
5252
protected static final String LOG_TAG = "InAppBrowserActivity";
5353
public static final String METHOD_CHANNEL_NAME_PREFIX = "com.pichillilorenzo/flutter_inappbrowser_";
54-
54+
5555
@Nullable
5656
public Integer windowId;
5757
public String id;
@@ -77,24 +77,29 @@ public class InAppBrowserActivity extends AppCompatActivity implements InAppBrow
7777
@Nullable
7878
public InAppBrowserChannelDelegate channelDelegate;
7979
public List<InAppBrowserMenuItem> menuItems = new ArrayList<>();
80-
80+
8181
@Override
8282
protected void onCreate(Bundle savedInstanceState) {
8383
super.onCreate(savedInstanceState);
8484

85-
if (savedInstanceState != null) {
86-
finish();
85+
Bundle b = getIntent().getExtras();
86+
if (b == null) {
87+
if (savedInstanceState != null) {
88+
finish();
89+
}
8790
return;
8891
}
8992

90-
Bundle b = getIntent().getExtras();
91-
if (b == null) return;
92-
9393
id = b.getString("id");
9494

9595
String managerId = b.getString("managerId");
9696
manager = InAppBrowserManager.shared.get(managerId);
97-
if (manager == null || manager.plugin == null|| manager.plugin.messenger == null) return;
97+
if (manager == null || manager.plugin == null || manager.plugin.messenger == null) {
98+
if (savedInstanceState != null) {
99+
finish();
100+
}
101+
return;
102+
}
98103

99104
Map<String, Object> settingsMap = (Map<String, Object>) b.getSerializable("settings");
100105
customSettings.parse(settingsMap);
@@ -111,7 +116,7 @@ protected void onCreate(Bundle savedInstanceState) {
111116
pullToRefreshLayout.channelDelegate = new PullToRefreshChannelDelegate(pullToRefreshLayout, pullToRefreshLayoutChannel);
112117
pullToRefreshLayout.settings = pullToRefreshSettings;
113118
pullToRefreshLayout.prepare();
114-
119+
115120
webView = findViewById(R.id.webView);
116121
webView.id = id;
117122
webView.windowId = windowId;
@@ -171,15 +176,13 @@ protected void onCreate(Bundle savedInstanceState) {
171176
Log.e(LOG_TAG, initialFile + " asset file cannot be found!", e);
172177
return;
173178
}
174-
}
175-
else if (initialData != null) {
179+
} else if (initialData != null) {
176180
String mimeType = b.getString("initialMimeType");
177181
String encoding = b.getString("initialEncoding");
178182
String baseUrl = b.getString("initialBaseUrl");
179183
String historyUrl = b.getString("initialHistoryUrl");
180184
webView.loadDataWithBaseURL(baseUrl, initialData, mimeType, encoding, historyUrl);
181-
}
182-
else if (initialUrlRequest != null) {
185+
} else if (initialUrlRequest != null) {
183186
URLRequest urlRequest = URLRequest.fromMap(initialUrlRequest);
184187
if (urlRequest != null) {
185188
webView.loadUrl(urlRequest);
@@ -242,8 +245,15 @@ public boolean onCreateOptionsMenu(Menu m) {
242245
}
243246

244247
MenuInflater inflater = getMenuInflater();
245-
// Inflate menu to add items to action bar if it is present.
246-
inflater.inflate(R.menu.menu_main, menu);
248+
try {
249+
// Inflate menu to add items to action bar if it is present.
250+
inflater.inflate(R.menu.menu_main, menu);
251+
} catch (Exception e) {
252+
e.printStackTrace();
253+
Log.e(LOG_TAG, "Cannot inflate com.pichillilorenzo.flutter_inappwebview_android.R.menu.menu_main." +
254+
"To make it work, you need to set minifyEnabled false and shrinkResources false in your build.gradle file.");
255+
return super.onCreateOptionsMenu(m);
256+
}
247257

248258
MenuItem menuSearchItem = menu.findItem(R.id.menu_search);
249259
if (menuSearchItem != null) {
@@ -607,9 +617,9 @@ public List<ActivityResultListener> getActivityResultListeners() {
607617
}
608618

609619
@Override
610-
protected void onActivityResult (int requestCode,
611-
int resultCode,
612-
Intent data) {
620+
protected void onActivityResult(int requestCode,
621+
int resultCode,
622+
Intent data) {
613623
for (ActivityResultListener listener : activityResultListeners) {
614624
if (listener.onActivityResult(requestCode, resultCode, data)) {
615625
return;

0 commit comments

Comments
 (0)