Automatically reopen Android app when it closes

I am working on an android application in which I have to always run it on my phone (the application is sending sms). Sometimes other users close it.

I need to debug my application when it closes.

Is it possible?

+3


source to share


2 answers


You can simply prevent the application from closing with the back button by overriding onBackPressed()

@Override
public void onBackPressed() {}

      

Now the user cannot exit the application by pressing the "Back" button.



OR to achieve what you want. Have this method ...

@Override
public void onDestroy() {
    super.onDestroy();
    Intent i = new Intent(this, ActivityName.class);
    startActivtiy(i);
}

      

This above code will start action when it is destroyed. I have not tested it to make sure it works.

0


source


The OS decides whether it needs to kill the application or not. Wanting an app to always work is a bad technical and UX decision.



Background services are designed to cover these use cases. Your UI may not necessarily be visible, but your service will register Broadcast receivers to receive event notifications and ultimately launch the app / show the notification.

0


source







All Articles