Question

I currently have widget for my app HireADroid bundled with the main application. I would like to unbundle the widget and release it as a separate offering. However - the widget is relying on Activities from the main app so I need to navigate between these two mainly calling particular Activity of the main app from the widget. So the basic idea - app can work without widget and the widget becomes the "add-on" option.

What is the "right" way to call app activities from the stand-alone widget? Do I convert the main app into a content provider? Can you point me to any code samples perhaps?

Happy New Year!

P.S. I'm not asking how to call Activities from the widget that is bundled in the same APK. The question specifically states that widget is distributed separately from the app it's calling

Was it helpful?

Solution

The basic idea is to use Intents:

  1. In the manifest, have your activity respond to certain actions using an <intent-filter>.
  2. In your widget code, create an instance of the android.content.Intent class for the action you've set your activity to respond to, and call startActivity on the Intent instance.

If the activity is contextual, you can use content URIs (you can create Intents for action/URI pairs) and also pass extra information via an 'extras' bundle (see Intent.getExtras).

More information available in the docs here:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top