Share Link - Perform action in background

http://stackoverflow.com/questions/2487281/share-link-perform-action-in-background

Question:

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 bringing 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.

Answer:

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.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值