Skip to content

Commit 55a7b23

Browse files
a7medevHeshamMegid
authored andcommitted
fix(android): get application through react context (#1069)
Jira ID: [\[INSD-10472\] \[Dream11\] Feature flag crashing IBG library ](https://instabug.atlassian.net/browse/INSD-10472)
1 parent 42b408b commit 55a7b23

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v12.2.0...dev)
4+
5+
### Fixed
6+
7+
- Fix an issue with `Instabug.init` on Android causing the app to crash while trying to get the current `Application` instance through the current activity which can be `null` in some cases by utilizing the React context instead ([#1069](https://github.com/Instabug/Instabug-React-Native/pull/1069)).
8+
39
## [12.2.0](https://github.com/Instabug/Instabug-React-Native/compare/v12.2.0...v12.1.0)
410

511
### Added

android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static com.instabug.reactlibrary.utils.InstabugUtil.getMethod;
44

5+
import android.app.Application;
56
import android.graphics.Bitmap;
67
import android.net.Uri;
78
import android.view.View;
@@ -59,6 +60,7 @@ public class RNInstabugReactnativeModule extends EventEmitterModule {
5960

6061
private InstabugCustomTextPlaceHolder placeHolders;
6162
private static Report currentReport;
63+
private final ReactApplicationContext reactContext;
6264

6365
/**
6466
* Instantiates a new Rn Instabug ReactNative module.
@@ -67,6 +69,9 @@ public class RNInstabugReactnativeModule extends EventEmitterModule {
6769
*/
6870
public RNInstabugReactnativeModule(ReactApplicationContext reactContext) {
6971
super(reactContext);
72+
73+
this.reactContext = reactContext;
74+
7075
//init placeHolders
7176
placeHolders = new InstabugCustomTextPlaceHolder();
7277
}
@@ -122,7 +127,10 @@ public void run() {
122127
final ArrayList<InstabugInvocationEvent> parsedInvocationEvents = ArgsRegistry.invocationEvents.getAll(keys);
123128
final InstabugInvocationEvent[] invocationEvents = parsedInvocationEvents.toArray(new InstabugInvocationEvent[0]);
124129
final int parsedLogLevel = ArgsRegistry.sdkLogLevels.getOrDefault(logLevel, LogLevel.ERROR);
125-
RNInstabug.getInstance().init(getCurrentActivity().getApplication(), token, parsedLogLevel, invocationEvents);
130+
131+
final Application application = (Application) reactContext.getApplicationContext();
132+
133+
RNInstabug.getInstance().init(application, token, parsedLogLevel, invocationEvents);
126134
}
127135
});
128136
}

0 commit comments

Comments
 (0)