android app上线后bug的处理

app上线后,后期维护显得尤为重要,今天给大家分享一下app上线后出现bug后的解决方法

1.继承Application类,重写onCreate方法

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.lang.Thread.UncaughtExceptionHandler;

import android.app.Application;

/**
 * App上线后 bug的处理
 * 
 */
public class MyApplication extends Application {
	
	@Override
	public void onCreate() {
		super.onCreate();
		System.out.println("application启动了....");
		//捕获异常
		Thread.currentThread().setUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
	}
	private class MyUncaughtExceptionHandler implements UncaughtExceptionHandler {
		//当有未捕获的异常的时候会调用
		//Throwable : 其实Exception和Errorfu父类
		@Override
		public void uncaughtException(Thread thread, Throwable ex) {
			System.out.println("哥捕获了异常");
			//将异常保存到文件中
			try {			
				//异常文件log.txt,可以判断返回给我们的服务器
				ex.printStackTrace(new PrintStream(new File("/mnt/sdcard/log.txt")));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
			//保存文件之后,自杀,myPid() : 获取自己的pid
			android.os.Process.killProcess(android.os.Process.myPid());
		}
		
	}
	
}
2.AndroidManifest.xml中设置android:name=".MyApplication"属性

<application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:hardwareAccelerated="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
<span style="white-space:pre">	</span><activity
            android:name="com.demo.bug.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>

                <!-- MAIN : 主界面,入口界面,其实java类型的main方法 -->
                <action android:name="android.intent.action.MAIN" />
                <!-- LAUNCHER : 在桌面上释放一个图标 -->
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity> ......
</application>
3.将bug.txt反馈回我们的服务器

转载于:https://www.cnblogs.com/smartbetter/p/5259250.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值