views:

1417

answers:

1

I currently have widget for my app Hire*A*Droid 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

A: 

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:

Roman Nurik
That's the first thing I did: created content URI intent-filter in the main app's manifest. However when I'm trying to call that Intent from my widget's code I get `android.content.ActivityNotFoundException: No Activity found to handle Intent { act=myapp://widget/search }`My intent filter on the activity is defined as <intent-filter> <action android:name="android.intent.action.VIEW" /> <data android:scheme="myapp" android:host="widget" android:path="search" /> </intent-filter>and I call it as `new Intent("myapp://widget/results")`
DroidIn.net
I suppose you cannot do it in 2 separate apps communicating with each other
DroidIn.net
I think you may be confusing actions (i.e. your.package.ACTION) and URIs (i.e. content://your.package/content/path). The first argument to the `Intent` constructor needs to be an action (i.e. `ACTION_VIEW`) and the *optional* second argument can be a URI.
Roman Nurik
Even after changing to the Action(String, Uri) constructor `new Intent(Intent.ACTION_VIEW, Uri.parse("myapp://widget/search"))` I get `ActivityNotFoundException`
DroidIn.net
I found what I was missing - the intent-filter has to have at least one category (I used DEFAULT). Thanks for your help
DroidIn.net