0

I write an activity which I'd like to behave (in terms of instatiating it) similar to command-line tools such as, let's say, sort (imagine: sort = my_application, pipe "|" = intent_resolution)

In Android world it would be that every intent is processed by my activity, and I still can go back.


Use case is like that: We have an Activity com.A.

  1. User runs it from home screen:

LAUNCHER/MAIN of com.A (screen Ax appears)

  1. Home button is pressed.

  2. Then user runs A with explicit intent

am -n com/.A -e some_extra (screen Ay appears - it's different because it depends on intent)

  1. Home button again.
  2. User runs A again (third time) from launcher icon:

LAUNCHER/MAIN of com.A (screen Ay appears, because Android 'thinks' that user wants previous activity. But he'd like to see Ax again - as a proper response for intent LAUNCHER/MAIN)


I can obtain such behaviour by setting launchMode=singleTask, so my every intent is processed by onCreate or onNewIntent. But in such case I lose history. So if A calls B and B calls A (A → B → A) I will lose first A. The same if A calls A (A → A) than I cannot go back.


Is this possible to set such a combination of <activity> manifest attributes or using other means to obtain that behaviour?

Note: if I change LAUNCHER/MAIN for any other intent it doesn't change anything.

sZpak
  • 247
  • 10

1 Answers1

0

It looks like that combination of

android:finishOnTaskLaunch="true"
android:finishOnCloseSystemDialogs="true"

and default launchMode works more or less as I need. I still haven't tested it that deeply and don't expect it gonna work 100% precise but at the moment it works fine.

I also tried to detect home button and then finish activity manually, but apparently it's not very reliable neither.


Edit: Downside of this solution is that every time phone rings or you just lock your screen then the app with such manifest is destroyed.

sZpak
  • 247
  • 10