What is the correct way to specify an intent action in a manifest file?

The tutorial says to use android.appwidget.action.APPWIDGET_UPDATE in the action element in XML intent-filter .

but

this is the value of the String constant ACTION_APPWIDGET_UPDATE in android.appwidget.AppWidgetManager

- I am new to Android, but in general programming it is recommended to use symbolic constants, rather than literal values.

Can I use android.appwidget.AppWidgetManager.ACTION_APPWIDGET_UPDATE in my XML file and not "android.appwidget.action.APPWIDGET_UPDATE"?

This is more a matter of good practice than a tear-off.

+4
source share
2 answers

Answer: no, Android does not allow, and I can not come up with a good reason. The question specifically asks about the standard Android string literal, not the string literal, so I do not accept another answer (which is still a good answer, so that you can transfer it).

0
source

Please use your target filter action value in the res / value / String.xml file and use it where it is needed, for example, manifest.xml, as well as other java files.

I think this is the best way to find. Since you should use the changes in only one place, and they are reflected in each mentioned place.

Thanks,

+1
source

Source: https://habr.com/ru/post/1386808/


All Articles