Issue
I am getting below error while sending color resource id from main app to library app (both is handled by me).
In main app, Theme is being changed dynamically so, I am passing the resource id of main app theme's primary color by adding it in intent extra as below
EDIT -- I am retrieving the theme's primary color as below in main app and sending it to libraray app.
private int getThemeColor() {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = getActivity().getTheme();
theme.resolveAttribute(R.attr.colorPrimary, typedValue, true);
@ColorInt int color = typedValue.data;
return color;
}
//passing primary color to library app activity via intent
intent.putExtra("PRIMARY_COLOR",themeColor);
In library app I am retrieving the resource id as below
primaryColor = intent.getIntExtra("PRIMARY_COLOR", 0)
val res: Resources =
packageManager.getResourcesForApplication(callerPackageName)
primaryColor = res.getColor(primaryColor) //This line throws error
Solution
Based on your code and the value in the exception, you are already retrieving color int from the intent, so you don't need to get it from resources, you can just use it as is. What you are instead doing right now, is trying to interpret the color in as color id which obviously doesn't exist, so you get an exception
Answered By - Sergei Kozelko
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.