以编程方式崩溃后重新启动应用程序 - Android
有没有办法让我的应用程序在崩溃时自动重新启动?我的应用程序只是一个简单的媒体渲染应用程序,但是它偶尔会崩溃(应该是这样)。这有可能吗?谢谢。我的代码看起来像这样
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
}
Is there a way for my to program my app to automatically restart itself whenever it crashes? My app is just a simple media rendering App, however it occasionally crashes ( it's supposed to ). Is this at all 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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将为你完成这项工作。
如何启动自动停止的android服务?
我仍然不明白为什么它会崩溃。
更新
为未捕获的异常创建一个处理程序,您为未捕获的异常注册一个处理程序
您在创建时
this will do the job for you.
How to start the automatically stopped android service?
still i don't understand why it is supposed to crash.
UPDATE
you create an handler for uncaught exception
in your on create, you register an handler for uncaught exception
我可能会迟到很多次,但我找到了解决您问题的二合一解决方案。
I might be late a lot, but I found 2 in 1 solution for your problem.