How do I within Android, if a function is called which is already running, cancel/stop that function then start it from the beginning?
My code looks like the below, basically throughout my application a given function( Important(); ) is called but rather than have that function run several times. I'd like to Cancel/stop it, then start it from the beginning?
How can I go about doing this?
Code:
public void Important() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Important();
}
@Override
protected void onResume() {
super.onResume();
Important();
}
I've already attempted the below making use of booleans. But it just stops a user from running the function again if already running? (which isn't what I'm trying to do)
I want, when it is called again. The running function is stopped. Then freshly run it
Code:
Boolean runningCode = false;
public void Important() {
if (runningCode== false) {
runningCode = true;
runningCode = false;
}
F.Y.I
Important() is called many times throughout my application, sometimes whilst Important() is still running. Hence the need for a solution to my question :-)
Tasks like resetting variables, formatting the page are carried out within
Important();, it is not running on a separate thread. These are tasks that need to be completed on the main UI thread