Android Question Getting back to the previously open app

slugger

Member
Licensed User
Longtime User
Hello,

consider the following example.

I am playing with one app, it doesn't matter which one, it may be Firefox, Whatsapp, a game or whatever else.

My program is made of an activity and a service started as StartForeground, and is currently running in the background.

I open the Notification Drawer and click my app's icon, that brings up my app's activity screen so I can check something (the progress of a download, the last messages received or something else).

Then I want to put my app's screen to the background *WITHOUT* destroying it (so Activity.Finish is not an option), I simply want to hide the graphical part of it, and I want to return to what I was doing before opening the notification drawer.

Is it possible to programmatically send my app's graphic activity to the background and return to the previously open app?

I am able to intercept the BACK key and send an intent to show my Home screen, that puts my activity in the background.

What I'd like to do is intercept the BACK key and land back exactly on the same app I was using before opening the notification drawer.

Any hints?


steve
 

slugger

Member
Licensed User
Longtime User
Hi Erel,

I thought Activity.Finish would destroy the graphical part of the program and force the Create sub to be called again, I will try to put it in the Pause sub when Userclosed is true and see if it works properly.

Thanks.
 
Upvote 0

slugger

Member
Licensed User
Longtime User
I just tried and, as I suspected, the CREATE sub is called again when I click the icon in the notification drawer.

That's no good.

I have a customlistview with a few hundreds items which are added a few every minute.

The Activity.Finish kills the graphic part of the program, in fact when I call again the program the old customlistview with all its items is gone.

Updating the list every time the app is reloaded is time consuming as it can take many seconds depending on the number of the items to show.

If I intercept the BACK key and send the intent to show the Home screen my app is simply sent to the background but the customlistview is preserved, in fact when I click again the icon in the notification drawer my app simply pops up with all the old items on the screen.
 
Upvote 0

slugger

Member
Licensed User
Longtime User
I use the same code found in your example, that is:

B4X:
clv3.Add(CreateListItem("Item #" & i, clv3.AsView.Width, 50dip), 50dip, "Item #" & i)

Inside the CreateListItem sub I add a few labels, fill them with text and add them to the panel.

With a few hundred panels added to the customlistview it can take several seconds to be recreated each time the activity is closed with Activity.finish.

Adding the items as the user scrolls the list might be a good idea I haven't thought about but I guess the fast vertical scrolling would still be full of pauses and lags.

I have tried to add 100 items on my crappy chinaphone with 4 cores at 1.2 Ghz and it takes about 2 seconds, when the customlistview holds a few hundreds the time of reloading is not acceptable.

I will keep trapping the BACK key to show the Home screen, I guess it is the best thing.
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
Although it requires a bit of a rejig of your code, you might find it worth checking out the UltimateListView library; assuming you have your items in some sort of list or map or database, ULV allows the list to be built very quickly, because it just creates views for those items that are visible, and reuses them as people scroll up and down.

I have a list of users online in one of my apps, or user search results, and using CLV I found that I was getting lots of ANR messages and skipped frames in the logs, especially with searches that showed lots of results. Switching to ULV has solved that, and certainly for me it's been worth the €25 and the time tweaking the code.
 
Upvote 0

slugger

Member
Licensed User
Longtime User
Thanks for all the info.

I am using the Flexible Table in place of the scrollview, the fact that it is in B4A code is a big plus so I can customize the ShowRow sub to suit my needs.

Loading about 2000 items (each with 5 labels on the screen) takes 3 seconds.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…