android 捕获线程出错 重启线程

设置捕获线程出错

Thread sendLocationTread = new Thread(sendUserLocationThread); sendLocationTread.setUncaughtExceptionHandler(exceptionHadler); sendLocationTread.start();

 

/**
	 * 百度地图获取不到位置 重启线程 最多重启5次
	 */
	private UncaughtExceptionHandler exceptionHadler = new UncaughtExceptionHandler() {
		private int restartTime = 0;
		private final static int MAXTIME = 5;

		@Override
		public void uncaughtException(Thread t, Throwable e) {
			if (restartTime < MAXTIME) {
				System.out.println("=restart");
				Thread thread = new Thread(sendUserLocationThread);
				thread.setUncaughtExceptionHandler(this);
				thread.start();
				restartTime++;
			}

		}
	};

  线程中就可以设置throw 这样就可以重启线程

if (BDERROR) {
				throw new RuntimeException();
			}

  

posted on 2013-08-13 16:19  冲锋的路上的兵  阅读(390)  评论(0编辑  收藏  举报