Share link - perform an action in the background

I have an application that will accept URLs from the embedded web browser via the Share menu item. I use the sending intent and everything works fine. However, I would like to accept the URL and process it in the background without bringing my application to the forefront. I do not want the user to really leave the web browser. It will notify the user that he has finished processing the URL using the Toast message. I'm just not sure what type of activity should be used for this.

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

+3
source share
2 answers

AFAIK, ACTION_SENDworks only for actions, not for services. Therefore, you will need to create an activity that separates things. However, if everything you do displays Toastand does not have a valid activity user interface, you can use Theme.NoDisplayto suppress the activity user interface otherwise:

<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 a complete example of this technique in one of my sample books .

+2
source

You should implement a background service that notifies your application when the URL processing is complete.

+1
source

Source: https://habr.com/ru/post/1737911/


All Articles