Android Question Remove app from recent list (or reset intent?)

Kevin

Well-Known Member
Licensed User
Longtime User
I am trying to exit my app from a button in a notification (which uses an intent). I have that sorted out fine. The problem is the way Android seems to store the last-used starting intent.

If I go to the recent apps list and press on my app, it starts then immediately stops the app because it is still using the last intent, which was telling the app to exit.

I know I can permanently prevent the app from appearing in the recent apps list by putting an entry in the manifest but ordinarily I do want it listed there.

So my question is: Can I reset the starting intent, or can I programmatically remove my app from the recent apps list?

If not, does anyone have a solution? I can't post my code right now but all it does is read the app's starting intent in Activity_Create and if it sees the "killapp" intent, it force-stops the app (ExitApplication).
 

Informatix

Expert
Licensed User
Longtime User
AFAIK, there's no mean to remove an entry in the recent apps list. But that shouldn't be too complicated to distinguish the different cases. If the FirstTime value of the Create event is not enough, use a boolean flag that you store somewhere. When it is true, you know that you have to exit, and when you exit, you set it to false, so there's no confusion when you restart.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Also, what you need is to set a flag in your intent:

public static final int FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
Added in API level 1
If set, the new activity is not kept in the list of recently launched activities.

Constant Value: 8388608 (0x00800000)

B4X:
Dim myIntent as Intent
myIntent.Flags = Bit.Or(myIntent.Flags, 8388608)
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
Also, what you need is to set a flag in your intent:



B4X:
Dim myIntent as Intent
myIntent.Flags = Bit.Or(myIntent.Flags, 8388608)

Interesting. I was messing with flags but this may be the way to go. Although I am using Barx's Notification Builder, which is where the Exit App button is pressed, so I can't really control the sending intent.

I tried several different ways of doing this. It sometimes works, sometimes doesn't. It varies depending on if you previously backed out of the app or switched tasks; whether the app is still mostly in memory or Android has killed it off... :confused: Sometimes it works how I would expect and other times the app closes itself until you re-open with a shortcut since it is reusing the old intent.

As for why I am killing the app rather than just finishing the activity... Yes, I am aware of how it should work, but try to convince the thousands of Android users out there who think they know better and complain when it "wastes memory" and "constantly runs in the background wasting precious CPU cycles." :rolleyes:
 
Upvote 0
Top