Closed koenniem closed 3 years ago
According to the docs, Android devices target API 30 (Android 11) or later receive a null key
when preferences are cleared. This does not happen to lower API versions since the listener is not triggered then.
Proposed fix:
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
String result = sharedPreferences.getString("detected_activity", "error");
Log.d("onSharedPreferenceChang", result);
if (key != null && key.equals("detected_activity")) {
Log.d("activity_recognition_flutter", "Detected activity: " + result);
this.eventSink.success(result);
}
}
Thanks, will fix.
Fixed in version 3.0.1
Remember to specify the plugin name in the title!
Device / Emulator and OS
Please complete the following information for each phone and/or emulator you're experiencing this bug on:
Describe the bug
In relation to issue #305, when enabling the foreground service the app crashes with a NullPointerException when trying to read the SharedPreference. In
ActivityRecognitionFlutterPlugin.class
:In this code,
key
isnull
causing an exception inif (key.equals("detected_activity")) {
This has also been reported earlier in issue #248.
Additional information
Stacktrace: