开发者

Share Link - Perform action in background

开发者 https://www.devze.com 2022-12-23 21:15 出处:网络
I have an application that will accept URLs from the built in web browser via the \"Share page\" menu item. I\'m using the send intent and it works just fine. However, I\'d like to accept a URL and pr

I have an application that will accept URLs from the built in web browser via the "Share page" menu item. I'm using the send intent and it works just fine. However, I'd like to accept a URL and process it in the background without bring开发者_运维知识库ing my application to the front. I don't want the user to have to actually leave the web browser. It will notify the user it has finished processing the URL with a Toast message. I'm just not sure what type of activity should be used for this.

A good example of this behavior is the "Read Later" instapaper application in the android market. Any help would be greatly appreciated.


AFAIK, ACTION_SEND only works for activities, not services. Hence, you will need to create an activity that shares things. However, if all you are doing is displaying a Toast and no actual activity UI, you can use Theme.NoDisplay to suppress the otherwise-empty activity UI from showing up:

<activity android:name="TwitterSender"
        android:label="@string/sender_name"
        android:theme="@android:style/Theme.NoDisplay">
    <intent-filter android:label="@string/sender_name">
        <action android:name="android.intent.action.SEND" />
        <data android:mimeType="text/plain" />
        <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter>
</activity>

You can see the complete example of this technique in one of my book samples.


You should implement a background service which notifies your application once it has finished processing the url.

0

精彩评论

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

关注公众号