Widget Not Updated on Launcher Restart

Widget not updated on launcher restart

Turns out I was spamming new RemoteViews() when I should have just called it once to produce the view, and then referred to that one instance when required. In my solution, I have a class variable which stores this single RemoteView instance, and a getter to access it.

After rebooting or upgrading the app, my Android widget stops updating

Add a call to super.onReceive() to your onReceive().

Explanation

If you look at the source for the base class onReceive(), you can see that it implements part of the framework logic for managing Widget lifecycle. (Also hinted at by the docs). It handles APPWIDGET_UPDATE and is, in fact, what's responsible for calling onUpdate() in the first place. (E.g., when the system boots up, and it needs to draw your initial widget, it sends your app an APPWIDGET_UPDATE, which gets passed to onReceive()). So, I'm not 100% sure how onUpdate() was ever getting called, in your case, but I assume you have some code somewhere else that calls updateAppWidget(), and that's the only reason your widgets appeared to work even momentarily.

Why App widget stops working after restarting laucher?

After restart, the restored view will be the one instantiated in IntentService, which is without OnClickPendingIntent.

To solve the problem, I should change icon only in update function in provider via broadcasts.

still a question, why the OnClickPendingIntent will work until launcher restart, after view is replaced.

Widget not updating in flutter

getData is async, so the execution of the body for setState terminates immediately, updating the state before the async result is delivered.
Since setState doesn't allow an async body you have to do things differently.

Given the code you've provided, you could do something like this:

onChanged: (String newValue) {
selectedCurrency = newValue;
print("Selected currency changed to $selectedCurrency");
getData();
}

and update the getData code like this:

void getData() async{
var bitCoinPrice1 = (await coinData.getPriceData('BTC$selectedCurrency')).toStringAsFixed(2);
setState({
bitCoinPrice = bitCoinPrice1;
});
}

This way the setState will be called after the await-ed operation is done.



Related Topics



Leave a reply



Submit