3

From the documentation, the constructor of RemoteViews is

public RemoteViews (String packageName, int layoutId)

The documentation says that packageName is "Name of the package that contains the layout resource".

  • Why is this needed?
  • Wouldn't the layoutId tell you everything that you need to know about the location of the layout resource?
  • What would you put as the package name?
  • Wouldn't it always be res->layout?
Andrew T.
  • 4,701
  • 8
  • 43
  • 62
committedandroider
  • 8,711
  • 14
  • 71
  • 126

2 Answers2

3

Since Sirlate has answered "Why is this needed?", I'll try to answer the rest of the questions.

Wouldn't the layoutId tell you everything that you need to know about the location of the layout resource?

No, layoutId, like other resources' ID is only a number. When you reference it through R.layout.some_layout, it actually refers back to the ID itself, as a number.

Wouldn't it always be res->layout?

Actually, not! You can put any resources in any folder (as long as inside /res) even if it's a layout resource. /res/layout/ is just a convenient folder since Android already defines it in the first place. After all, Android will just refer the resources as ID number.

What would you put as the package name?

The package name of the app you want to use the layout, as stated by Sirlate.

Why is this needed?

In addition to Sirlate's answer, if you only have a resource ID, it will be impossible for the OS to decide from which package/app the layout is.

Andrew T.
  • 4,701
  • 8
  • 43
  • 62
2

In case you have multiple widget and app and you signed them all with the same key (Signing the applications with the same key allows them access to each other's data.), then you may have access to them too which does not have the same package name.

Sadegh
  • 2,669
  • 1
  • 23
  • 26