开发者

Android - Calling Activity from widget

开发者 https://www.devze.com 2022-12-14 21:35 出处:网络
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 Activitie

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:

  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:

  • http://developer.android.com/guide/topics/intents/intents-filters.html
  • http://developer.android.com/reference/android/content/Intent.html
0

精彩评论

暂无评论...
验证码 换一张
取 消