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 trial

Android

Pending 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 ?

Sure, 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
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Judah Devasahayam
Full Stack JavaScript Techdegree Graduate 22,610 Points

When 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.

Sure, 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
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Judah Devasahayam
Full Stack JavaScript Techdegree Graduate 22,610 Points

This 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?

Sure, for ( int id: appWidgetIDS){ Intent intent = ............. ; PendingIntent = PendingIntent.getBroadcast(context,id,intent,FLAG_UPDATE_CURRENT); }

Yes, it works as expected.