2

Searched and not found solution. Does anyone have same problem and find a way to resolve it?

Having activity (with launchMode="singleTask") which handles the sharing.

When activity is running, open camera app to do sharing through this app. This activity's onNewIntent(Intent intent) is called with Intent { act=android.intent.action.SEND...}. The sharing request is handled, so far so good.

Then hit "Back" button to dismiss the app. Now open the running app tray (long press the home button) and pick this app to open it.

The app's activity onCreate() is called with savedInstanceState==null, and the same intent for last sharing request is passed in: { act=android.intent.action.SEND ...}.

In this case it will always open the app in handling some sharing request, which has been already handled before.

Is there way to avoid the consumed intent to be passed in again?

Thanks! /L

lannyf
  • 9,865
  • 12
  • 70
  • 152
  • I do not think you can avoid the consumed intent to be passed again. But you can check if the activity is being launched from history, and if it is the case do not handle it again. Check out this answer: http://stackoverflow.com/a/25535915/1970641 – tato.rodrigo Oct 08 '14 at 20:09
  • Thanks Tato. The problem is some time you can't tell if the activity is relaunched. In the case of after hitting 'Back" button and re-open the app from the running app tray, the onCreate() is passed in with saveInstanceState==null, so it is same as a fresh start. – lannyf Oct 08 '14 at 20:19
  • That is why I'm using a combination. Did you checked the `boolean launchedFromHistory = intent != null ? (intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0 : false;` part of the answer? – tato.rodrigo Oct 08 '14 at 20:24

1 Answers1

0

Thanks Tato! The Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY is the solution for this case. For details refer to Tato's answer in stackoverflow.com/a/25535915/1970641.

lannyf
  • 9,865
  • 12
  • 70
  • 152
  • I use singleTop and `getFlags & FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY ` returns always true.. – user25 Apr 22 '18 at 15:46