Android Alarm Manager triggers once its time is reached at the moment. When that means it triggers also its callback function to handle some jobs according to the structure. However, when sending message or parameters to use it on the callback function to do some tasks, it is unclear that how I can set a specific alarm with a certain value on Alarm Manager Function.
await AndroidAlarmManager.oneShot(
const Duration(seconds: 5),
// Ensure we have a unique alarm ID.
Random().nextInt(pow(2, 31)),
callback,
exact: true,
wakeup: true,
);
That call function is below here. But it can't get passed variable from its parent functions.
// The callback for our alarm
static Future<void> callback() async {
print('Alarm fired!');
// Get the previous cached count and increment it.
final prefs = await SharedPreferences.getInstance();
int currentCount = prefs.getInt(countKey);
await prefs.setInt(countKey, currentCount + 1);
// This will be null if we're running in the background.
uiSendPort ??= IsolateNameServer.lookupPortByName(isolateName);
uiSendPort?.send(null);
}
My main purpose is to use Android Alarm Manager as reminder application.