Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is base intent?

from : http://developer.android.com/guide/topics/manifest/activity-element.html

android:relinquishTaskIdentity

Whether or not the activity relinquishes its task identifiers to an activity above it in the task stack. A task whose root activity has this attribute set to "true" replaces the base Intent with that of the next activity in the task.

What is base intent here?

like image 350
q126y Avatar asked Mar 13 '23 15:03

q126y


1 Answers

The base intent is the root intent that initially launched your app.

Most common one is probably the one that any app has when responding to the touch on the app icon. The LAUNCHER intent.

But it can be a custom one, for example, when you respond to custom scheme/url. But here is the trick and how relinquishTaskIdentity can be useful :

Say you start your app with the launcher icon. Your base intent is now the default one.

Now, say your app is completely killed (or you've backed with the hardware icon until your app closes) and you use a custom scheme/url to open your app, at this point the base intent is not the default one. It's the one generated from the scheme/url you clicked on and may contain custom data also. Now if you just close your app with the home button and reopen it, you will just resume where you were at. But if you back, back, back... with the hardware button until your app closes there is the trick : reopening it from the recent apps/multitasking view will reuse the base intent to open it and in this particular case it will still be your custom scheme/url intent and this can be very annoying.

Why annoying? Say the scheme/url your user clicked on was used to auto login and he succeeded: you don't really want to process this url/intent again just because your user backed up until its app closed and reopened it via recent apps/multitasking view, right?

Use relinquishTaskIdentity! This is very dependent to your setup and how your app is configured as for the Activities versus Fragments, but here is an example:

In the particular case I mentioned with the auto login via a link you could have an Activity that is dedicated and is only responding to scheme/url. This same activity should be different than the one flagged as LAUNCHER. and using the property relinquishTaskIdentity="true" on it will make the base intent become any subsequently shown activity via that one.

So what's the benefit in our case? The user can't enter the app with a custom scheme/url generated intent anymore unless he/she really clicked on one supported by your app.

like image 146
vincentroyc Avatar answered Mar 24 '23 18:03

vincentroyc