Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJoan Santiago Cabezas Monroy
Courses Plus Student 561 PointsPending intent change the color
Hi, in the video Making it change the color, why the professor is creating a new variable called realAppWidgetIds instead of just passing in the pending intent id the actual id ?
Joan Santiago Cabezas Monroy
Courses Plus Student 561 PointsSure, https://teamtreehouse.com/library/making-it-change-color MInute 4 aprox the professor there create and int[] realAppWidgetIds and go throught this array instead of the appWidgetIds received in the parameter
4 Answers
Judah Devasahayam
Full Stack JavaScript Techdegree Graduate 22,610 PointsWhen he initalizes the realAppWidgetIds
variable he passes the context variable, int [] realAppWidgetIds = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, WidgetProvider.class));
, what Context does is it allows the application to access application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.
Joan Santiago Cabezas Monroy
Courses Plus Student 561 PointsSure, thanks for your explanation but i want to know,(this was a solution for differentiate the pending intents, right ? ) so i decided to pass the individual widget id instead of 0 as pendingintentId parameter, So, i want to know why go throught this id's was the solution selected by the professor.
Judah Devasahayam
Full Stack JavaScript Techdegree Graduate 22,610 PointsThis way is more reliable according to the instructor, even I don't know why lol. Would you care to explain how you passed the individual widget Id's instead of zero?
Joan Santiago Cabezas Monroy
Courses Plus Student 561 PointsSure, for ( int id: appWidgetIDS){ Intent intent = ............. ; PendingIntent = PendingIntent.getBroadcast(context,id,intent,FLAG_UPDATE_CURRENT); }
Judah Devasahayam
Full Stack JavaScript Techdegree Graduate 22,610 PointsDoes it still work? as in does it yield the same results?
Joan Santiago Cabezas Monroy
Courses Plus Student 561 PointsYes, it works as expected.
Judah Devasahayam
Full Stack JavaScript Techdegree Graduate 22,610 PointsJudah Devasahayam
Full Stack JavaScript Techdegree Graduate 22,610 PointsWhich video are you talking about? can you please tell the topic's name?