System equivalent in Android?

I know this call shouldn't be made, but for now it's the only thing that stops working quickly enough.

Basically, after returning the application from the background (or using the End DDMS Application button), some static variables are null. I would like to restart the activity to stop the crashes and so all values ​​are updated.

For now, System.exit (0) has done what I want, but I know it is not good.

I tried finish()

it but it doesn't stop the action fast enough, it keeps on executing some instructions which still crashes.

Any suggestions on how to manage this issue.

+3


source to share


3 answers


The standard way to close your Android app is very simple:

finish();

      



or more complicated way:

android.os.Process.killProcess(android.os.Process.myPid());

      

+2


source


Only in android api 21> you can use>

getActivity().finishAndRemoveTask(); 

      

Ends all activities in this task and removes them from the recent task list.



It stops the application as quickly as System.exit (0). But is it better System.exit(0)

? I dont know...

- EDIT -

In this question enter link description here you can see all kinds of ways to stop your application.

+2


source


As per the docs for Activity.finish () :

Call this when your activity is finished and needs to be closed. ActivityResult is propagated to those who launched you via onActivityResult ().

When you call System.exit (), you are effectively shutting down the JVM; by shutting down, you are allowing the Android JVM to do its cleanup.

+1


source







All Articles