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 A开发者_如何学Pythonctivities 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
The basic idea is to use Intents:
- In the manifest, have your activity respond to certain actions using an
<intent-filter>
. - 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 callstartActivity
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:
- http://developer.android.com/guide/topics/intents/intents-filters.html
- http://developer.android.com/reference/android/content/Intent.html
精彩评论