Android Question How to end an Activity from another module?

andrewj

Active Member
Licensed User
Longtime User
Hi,

I have two activities which the user will switch between, a web browser and a file browser. I want to try and avoid completely re-loading these activities each time the user switches, as that could be quite costly on time, bandwidth etc., so I don't force each one to finish in its Activity_Pause routine.

The problem I have is that if the user has used both activities and opts to close down the app from the Main activity (the file browser), then it doesn't cleanly close the web browser. I've tried using ExitApplication but that doesn't work cleanly, and the problem is very difficult to debug because the behaviour in debug mode is different to release mode.

Is there any way to force the browser activity to close from the Main activity? If there was an EndActivity() similar to StartActivity() that would work. I have tried a CallSub() to a routine in the browser which in turn calls Activity.Finish, but that doesn't seem to work.

Any ideas?
Thanks
Andrew
 
Alternatively is there a way to find out if a given activity is the "last" one, so only that one calls ExitApplication?
Thanks
Andrew
 
Upvote 0
Hi Erel,
I really don't want to have to completely re-architect my application for this. I also want the application to positively close when the user selects "exit", as it's handling secure data and the user must login again to access it.

Is there a better way to find out which activities are active and close them all down?
Andrew
 
Upvote 0
Thanks Erel,
I had tried something similar, but without success. However putting the flag in a separate code module and making sure that's the first thing each resume() checks seems to have done the trick.
Thanks for your help
Andrew
 
Upvote 0
Hi Erel,
Your solution doesn't quite work. The app appears to exit, but leaves a "phantom" process running without any active activities. When I try and restart the app picks up the value of the global "exit" flag and just exits immediately. I have to do a "force stop" before I can restart.

Is there any way to detect when the last activity closes so I can then call ExitApplication and be sure the app has closed?

Thanks
Andrew
 
Upvote 0
I had a very similar problem. This is my solution:

1. (throughout) callsubdelayed to make the calls between modules
2. (EXCEPT in Main) Activity.finish after each callsubdelayed to terminate the activity
3. (in situations which allow the user to request termination of the complete app)
set main.bForceClose (global exit flag) = true before Activity.finish
4. (in Main) Sub Activity_Resume
If bForceClose Then Activity.finish

NB In Main (in Activity_create - firsttime)
I had to put If FirstTime OR bForceClose Then do first-time-stuff
I don't fully understand why this is needed, but it works for me.
 
Upvote 0
Back
Top