Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android remove data from getintent

I have an activity for handling deeplink which is a browsable activity

suppose user clicks a link on another app and my browsable activity handles that intent

and start the app, , then user minimise the app by pressing back button

class code for handling intent data

Uri link = getIntent().getData();

if user reopen app from running tasks getIntent() still have data

onDestroy method of browsable activity

@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
setIntent(null);

}

setIntent(null) not working

so my question is how can i remove data from intent permanently

like image 654
Nishant Tanwar Avatar asked Dec 26 '22 04:12

Nishant Tanwar


2 Answers

I am a little late on the answer here but I was dealing with a similar issue and found a solution. The reason you are still seeing data in the intent is because your app was originally started with an intent that contained data. That original intent is stored somewhere in Androids' ActivityManager and is immutable, to my understanding. When user reopens the app from "recent tasks", Android uses that original intent to recreate the application.

There is a workaround to this, however. In your apps onCreate() method, you can check to see if the Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY is set, which would allow your app to distinguish if it is being started from "recent tasks" or not, and therefore, you can avoid using the data contained in the intent.

Putting the following snippet in your onCreate() method would return true if the app is being opened from "recent tasks"

(getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0)

like image 138
km1234 Avatar answered Dec 28 '22 05:12

km1234


you have to remove data one by one key. i think you can't remove all data with one line.

if you want to remove specific key than you should use ==> getIntent().removeExtra("key"); or

getIntent().setAction("");

it will remove your data.

for more ==> Clearing intent

like image 25
Aiyaz Parmar Avatar answered Dec 28 '22 06:12

Aiyaz Parmar