Skip to content

[INSD-9704] Fix The onInvoke Callback #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-Flutter/compare/v11.12.0...dev)

### Fixed

- Fix an issue with the `onInvoke` callback not being called and causing `Instabug.show` to break on Android ([#369](https://github.com/Instabug/Instabug-Flutter/pull/369)).

## [11.12.0](https://github.com/Instabug/Instabug-Flutter/compare/v11.10.1...v11.12.0) (May 30, 2023)

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.instabug.bug.BugReporting;
import com.instabug.flutter.generated.BugReportingPigeon;
import com.instabug.flutter.util.ArgsRegistry;
import com.instabug.flutter.util.ThreadManager;
import com.instabug.library.Feature;
import com.instabug.library.OnSdkDismissCallback;
import com.instabug.library.extendedbugreport.ExtendedBugReport;
Expand Down Expand Up @@ -132,9 +133,17 @@ public void bindOnInvokeCallback() {
BugReporting.setOnInvokeCallback(new OnInvokeCallback() {
@Override
public void onInvoke() {
flutterApi.onSdkInvoke(new BugReportingPigeon.BugReportingFlutterApi.Reply<Void>() {
// The on invoke callback for Flutter needs to be run on the
// main thread, otherwise, it won't work and will break the
// Instabug.show API
ThreadManager.runOnMainThread(new Runnable() {
@Override
public void reply(Void reply) {
public void run() {
flutterApi.onSdkInvoke(new BugReportingPigeon.BugReportingFlutterApi.Reply<Void>() {
@Override
public void reply(Void reply) {
}
});
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.instabug.flutter.util;

import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;

public class ThreadManager {
// TODO: migrate to Flutter's TaskQueue
public static void runOnBackground(Runnable runnable) {
AsyncTask.execute(runnable);
}

public static void runOnMainThread(Runnable runnable) {
new Handler(Looper.getMainLooper()).post(runnable);
}
}