plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

Doesnt support other plugins in Alarm manager?

Open AkhilSajiCodzoc opened this issue 4 years ago • 7 comments

i dont know this is an issue or bug.So im writing it.I wrote an alarm manager function to execute certain task periodically.its firing periodically.But the problem is i cant use certain plugin inside that .I used shared preference plugin to take some date from locally.But alarm manager function return null on that.I dont know why.its only happens inside that Alarm manager static function.I just used another plugin Getstorage to do the similar thing again.But result was similar. In my case i am just tryin to build a wallpaper App.I just wanna change wallpaper periodically.There are numerous categories like nature,bike,car etc. for selection.If user select one category.Then i just fired an alarm mnager and should have to do automatically change wallpaper according to the category.Due to the static function of alarm manager, for knowing selected category i just wrote those to the locally.So for grabbing it in alarm manager static function, im used shared preferebce and Getstorage plugins.But both of them canot works as expected in alarm manager.I dont know why.Is this a bug or is this due to static function of alarm manager? Is there any solution or is there any idea to overcome it.

AkhilSajiCodzoc avatar Aug 18 '21 08:08 AkhilSajiCodzoc

I have tried many ways to make things work correctly but all them has failed...

I've declared a global SharedPrerences (out of any scope) and call sharedpreferences.setString() to write a value to storage inside my function called periodically by android_alarm_manager_plus.

setString return true, telling me that the value has been stored !

In the main isolate, my app is returning null when I attempt read the value from sharedpreferences.

I don't understand why my function fired by the plugin, isn't saving the value...

chazgps avatar Aug 23 '21 09:08 chazgps

@chazgps i dont know why this happens.may be this is due to static functionality of alaram manager.Any way, have to do some stuffs using method channel to implement this.I triedwith different plugins.They all have same results.They only executes pure dart codes,not all the flutter plugins.

AkhilSajiCodzoc avatar Sep 02 '21 05:09 AkhilSajiCodzoc

My workaround was using IsolateNameServer.registerPortWithName in main isolate to register a named port. Then, in alarm isolate, i'm using IsolateNameServer.lookupPortByName to find this port and send the results to main isolate to be saved by SharedPreferences.

chazgps avatar Sep 02 '21 10:09 chazgps

At the very least, we need better documentation for applying isolate in this situation.

thomassth avatar Dec 05 '21 11:12 thomassth

This is caused by this issue https://github.com/flutter/flutter/issues/98473#issuecomment-1041895729

You can also find a workaround there.

SoftXperience avatar Apr 22 '22 13:04 SoftXperience

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

github-actions[bot] avatar Jun 22 '22 00:06 github-actions[bot]

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

github-actions[bot] avatar Sep 21 '22 00:09 github-actions[bot]