Restart app programmatically after crash – Android
•
Android
Is there any way I can make my application restart automatically when it crashes? My application is just a simple media rendering application, but it crashes occasionally (it should). Is this possible? Thanks. My code looks like this
public void Play(){ if(mp != null) {
mp.reset();
mp.release();
mp = null;
}
AudioRenderer mr = new AudioRenderer();
mp = mr.AudioRenderer(filePath);
}
private class AudioRenderer extends Activity {
private MediaPlayer AudioRenderer(String filePath) {
File location = new File(filePath);
Uri path = Uri.fromFile(location);
mp= MediaPlayer.create(this, path);
}
return mp
}
resolvent:
This will finish the work for you
How to start the automatically stopped android service?
I still don't understand why it should collapse
UPDATE
You create a handler for uncapped exceptions
private Thread.UncaughtExceptionHandler onRuntimeError= new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread thread, Throwable ex) {
//Try starting the Activity again
};
In your creation, you register a handler for uncapped exceptions
@Override
protected void onCreate() {
super.onCreate();
Thread.setDefaultUncaughtExceptionHandler(onRuntimeError);
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码