Skip to content

Commit

Permalink
fix(android): get application through react context (#1069)
Browse files Browse the repository at this point in the history
Jira ID: [\[INSD-10472\] \[Dream11\] Feature flag crashing IBG library ](https://instabug.atlassian.net/browse/INSD-10472)
  • Loading branch information
a7medev authored and HeshamMegid committed Dec 7, 2023
1 parent 42b408b commit 55a7b23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v12.2.0...dev)

### Fixed

- 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)).

## [12.2.0](https://github.com/Instabug/Instabug-React-Native/compare/v12.2.0...v12.1.0)

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

import android.app.Application;
import android.graphics.Bitmap;
import android.net.Uri;
import android.view.View;
Expand Down Expand Up @@ -59,6 +60,7 @@ public class RNInstabugReactnativeModule extends EventEmitterModule {

private InstabugCustomTextPlaceHolder placeHolders;
private static Report currentReport;
private final ReactApplicationContext reactContext;

/**
* Instantiates a new Rn Instabug ReactNative module.
Expand All @@ -67,6 +69,9 @@ public class RNInstabugReactnativeModule extends EventEmitterModule {
*/
public RNInstabugReactnativeModule(ReactApplicationContext reactContext) {
super(reactContext);

this.reactContext = reactContext;

//init placeHolders
placeHolders = new InstabugCustomTextPlaceHolder();
}
Expand Down Expand Up @@ -122,7 +127,10 @@ public void run() {
final ArrayList<InstabugInvocationEvent> parsedInvocationEvents = ArgsRegistry.invocationEvents.getAll(keys);
final InstabugInvocationEvent[] invocationEvents = parsedInvocationEvents.toArray(new InstabugInvocationEvent[0]);
final int parsedLogLevel = ArgsRegistry.sdkLogLevels.getOrDefault(logLevel, LogLevel.ERROR);
RNInstabug.getInstance().init(getCurrentActivity().getApplication(), token, parsedLogLevel, invocationEvents);

final Application application = (Application) reactContext.getApplicationContext();

RNInstabug.getInstance().init(application, token, parsedLogLevel, invocationEvents);
}
});
}
Expand Down

0 comments on commit 55a7b23

Please sign in to comment.