1

I want to add the ability to share an image or link through my application. For this I added in the manifest those filters

<activity android:name="MyActivity" 
          android:launchMode="singleTask"
          android:screenOrientation="portrait"
>
    <intent-filter>
       <action android:name="android.intent.action.SEND" />
       <category android:name="android.intent.category.DEFAULT" />
       <data android:mimeType="image/*" />
    </intent-filter>
    <intent-filter>
       <action android:name="android.intent.action.SEND" />
       <category android:name="android.intent.category.DEFAULT" />
       <data android:mimeType="text/plain" />
   </intent-filter>
</activity>

this activity is basically the main one, I mean when the user will launch the application, this activity will be open.

now, when I swipe the application and share a youtube link through my application I get the data and it works fine, the problem is when I launch the application then press the home button (in this case the application is on background), and then try to share a youtube link I don't get the data from the intent.

any suggestions?

Noorul
  • 3,040
  • 2
  • 28
  • 45
Elior
  • 2,948
  • 6
  • 33
  • 60

3 Answers3

1

it seems you are putting the data handling code inside your onCreate() .

try putting the data handling code inside your onStart() .

mhdjazmati
  • 3,804
  • 1
  • 20
  • 32
1

When you share a link, the third-party application gives you data to share when it opens your application. But when you press the home button, data are not stored. Then, when you will back, data will be lost.

So, you need to store data when you retrieve data from the third-party application in a variable (for example).

Now, you can retrieve data with onStart() function and display on your view.

TIP: I guess you can use Singleton (also known as anti-pattern: read more).

Community
  • 1
  • 1
Loic P.
  • 643
  • 6
  • 15
1

Looks like you should add the handling not only in onCreate but as well in onNewIntent method. singleTask forces android to deliver the intent via onNewIntent if the activity is already created.

jakubbialkowski
  • 1,236
  • 12
  • 21