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
Android Studio: Exclude Resource File Under Resources Sourcesets
JSONarray Cannot Be Converted to JSONobject Error
Emulator: Warning: Quick Boot/Snapshots Not Supported on This Machine
How to Zoom + Crop a Image and Display the Croped Image on Imageview
<Select> Not Working in Phonegap App on Android 2.3.3
How Open New Activity Clicking an Item in Listview
I'M Getting a Nullpointerexception When I Use Action_Image_Capture to Take a Picture
How to Put Recyclerview Inside Nestedscrollview
Using Picasso Library with Listview
Why Do Listview Items Not Grow to Wrap Their Content
Android - Correct Use of Invalidateoptionsmenu()
How to Add Firebase-Admin to My Android Project
Widgets Don't Respond When Re-Added Through Code
How to Handle App Lifecycle with Flutter (On Android and iOS)
CSS - Background-Size: Cover; Not Working in Firefox
Does Edittext.Gettext() Ever Returns Null
Import .R Cannot Be Resolved When I Import Actionbarsherlock