编程崩溃后重新启动应用程序

编程崩溃后重新启动应用程序

本文介绍了编程崩溃后重新启动应用程序 - Android电子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有我对我的应用程序时,它崩溃自动重启本身编程的方法吗?我的应用程序仅仅是一个简单的媒体渲染应用程序,但它偶尔会崩溃(它应该)。这是在所有可能的?谢谢。我的code看起来像这样

 公共无效播放(){如果(熔点!= NULL){
             mp.reset();
             mp.release();
             熔点=无效;
         }
AudioRenderer MR =新AudioRenderer();
MP = mr.AudioRenderer(文件路径);
}私有类AudioRenderer延伸活动{
私人的MediaPlayer AudioRenderer(字符串文件路径){
文件位置=新的文件(文件路径);
URI路径= Uri.fromFile(位置);
MP = MediaPlayer.create(这一点,路径);
}
回MP
}


解决方案

这将做的工作适合你。

How启动自动停止的Andr​​oid服务?

我还是不明白为什么它应该崩溃。

更新

您创建未捕获的异常处理程序的

 私人Thread.UncaughtExceptionHandler onRuntimeError =新Thread.UncaughtExceptionHandler(){
        公共无效uncaughtException(线程线程,可抛出前){
            //尝试启动活动再次
    };

在上创建,您注册未捕获的异常处理程序的

  @覆盖
    保护无效的onCreate(){
        super.onCreate();
        Thread.setDefaultUncaughtExceptionHandler(onRuntimeError);
    }

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
}
解决方案

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

    private Thread.UncaughtExceptionHandler onRuntimeError= new Thread.UncaughtExceptionHandler() {
        public void uncaughtException(Thread thread, Throwable ex) {
            //Try starting the Activity again
    };

in your on create, you register an handler for uncaught exception

    @Override
    protected void onCreate() {
        super.onCreate();
        Thread.setDefaultUncaughtExceptionHandler(onRuntimeError);
    }

这篇关于编程崩溃后重新启动应用程序 - Android电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 23:47