1

What is meta-data tag in a widget provider?

<meta-data android:name="android.appwidget.provider" android:resource="@xml/providerinfo"/>
  • it says that app widget provider info is in "providerinfo.xml" file which is in xml folder.
  • it says that app widget layout is in "providerinfo.xml" file which is in xml folder.
  • option 1 is true, and it also says that this is not a broadcast receiver, it is a app widget provider.
  • option 2 is true, and it also says that this is not a broadcast receiver, it is a app widget provider.

Answer: C option 1 is true, and it also says that this is not a broadcast receiver, it is a app widget provider.
Description: it says that app widget provider info is in "providerinfo.xml" file which is in xml folder. it also says that this is not a broadcast receiver, it is a widget provider.

2

What is action APPWIDGET_UPDATE in a widget?

<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
  • This has to be used with widgets. Even if we don't use it there is no problem.
  • This has to be used with widgets. Even if we don't use it there is no problem. This has to be used with widgets, if we don't use it then onUpdate function of appWidgetProvider class will not be called and widget will not be updated.
  • This has to be used with widgets, if we don't use it then our widget application will crash.
  • This has to be used with widgets, if we don't use it then our phone home screen application will crash.

Answer: B This has to be used with widgets, if we don't use it then onUpdate function of appWidgetProvider class will not be called and widget wil not be updated.
Description: with out tag android.appwidget.action.APPWIDGET_UPDATE, android will not update the widget. Generally widgets are used as shortcuts and to display some dynamically changing content on the home screen.
If we don't use action APPWIDGET_UPDATE, then the dynamic content of widget will not get updated.

For eg : if we are using cricket score update widget on the home screen, and if we forget to give this action, then cricket widget will not update with the latest cricket score.

3

What is the tag used in manifest file to create widgets?

  • Service tag
  • Activity tag
  • Receiver tag
  • Widget tag.

Answer: C Receiver tag
Description: Since AppWidgetProvider is the derived class of BroadCastReceiver, so we have to use Receiver tag in manifest file.
When ever there is some content to be changed in the widget, system will broadcast that content to our widget. So widget is more of like a receiver.

4

What does app widget provider info xml will contain?

  • i. it will contain a reference to initial layout xml file.
  • ii. it will also contain what is the min width & height of the widget.
  • iii. it will contain the time in milli-seconds, which tells how many seconds once widget has to be updated.
  • i
  • i & ii
  • i, ii, & iii
  • i & iii

Answer: C i, ii, & iii
Description: 1. it will contain a reference to initial layout xml file. 2. it will contain what is the min width & height of the widget. 3. it will also contain the time in milli-seconds, which tells how many seconds once widget has to be updated.

5

what is the root tag used for app widget provider info xml file?

  • <appwidget>
  • <widget>
  • <appwidget-provider>
  • <appwidget-provider-info>

Answer: C <appwidget-provider>
Description: <appwidget-provider>

6

Which of the below components will be mostly used when writing or implementing an app widget provider class?

  • i. RemoteViews
  • ii. AppWidgetManager
  • iii. PendingIntent
  • i
  • i & ii
  • i, ii, & iii
  • ii

Answer: C i, ii, & iii
Description: AppWidgetManager : is the class used to update the widget.

Remoteview : is a view which can be displayed in other process.
When we create a widget, finally we will host that widget in home scree application (not our application). Since widget view will be in different application, to update those views we have to use the concept of RemoteViews.

Pending Intent : use it when you want to perform some intent operation at later point of time.
Since we don't know when user may click on our widget, we have to write a pending intent which will be triggered on clicking that widget to start our application activity.

Mostly when we are writing a widget, we will be using all the above components.

7

Widget and widget host : which of the below options are true about widgets?

  • The app which holds other applications widgets is called as widget host.
  • The app which holds other applications widgets is called as widget app.
  • Once we create a widget it will be automatically added to our home screen.
  • Widgets are like shortcuts, on clicking it will respond, but we can't change the contents of a widget.

Answer: A The app which holds other applications widgets is called as widget host.
Description: The app which holds widgets of other applications is called as widget host. Contents of a widget can change dynamically. (Widget is like a dynamic shortcut).

8

How to create or implement a widget in android?

  • i. To create widget we have to create a class that extends BroadCastReciver directly.
  • ii. To create widget we have to create a class that extends AppWidgetProvider directly.
  • iii. AppwidgetProvider inherits BroadCastReceiver.
  • i
  • ii
  • ii & iii
  • none of the above are true.

Answer: C ii & iii
Description: To create a widget we have to create a class that extends AppWidgetProvider. This class is inherited from BroadCastReceiver, since it has to receive the widget updates over some period of time.