Dear Klaus & Erel,
As Klaus suggested, I did put a "exitprog" variable.
I have three activities,
The first one is some settings, and I "activity.finish" it before I launch the second activity. But the first activity gives variables to the second activity, so although if I finish the first activity before opening the second, the program still runs in the background. So in the first activity, I put "secondactivity.exitprog=true" and then "ExitApplication" command.
The third activity however, must not close or reload the second activity and it also gives variables to the second activity. So, if I make changes in itand return to the second one, I simply "activity.finish" it. But if I want to close the app from the third one, I put "secondactivity.exitprog=true". So the second activity closes the app by "ExitApplication".
This is the workaround I found. Thank you for your help.