酷派大神x7应用重叠,怎么解决

2250人阅读
android知识点(6)
android开发中经常会遇到程序异常,而已常常会遇到一出现异常APP就自动重启了,而已如果你的项目中应用到Fragment的切换的话,会出行页面重叠的现象。今天为了解决这个问题看了不少大牛的博客。最后终于把问题解决了,下面就把解决的方法做一个介绍。
总的问题解决定向是处理崩溃异常的方法。先说说我前面尝试的不成功的方法。
一、写一个类实现UncaughtExceptionHandler 接口
import android.app.AlarmM
import android.app.PendingI
import android.content.C
import android.content.I
import android.os.L
import android.util.L
import android.widget.T
* Created by willkong on .
public class UnCeHandler implements Thread.UncaughtExceptionHandler {
private Thread.UncaughtExceptionHandler mDefaultH
public static final String TAG = "CatchExcep";
public UnCeHandler(MyApplication application){
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
this.application =
public void uncaughtException(Thread thread, Throwable ex) {
if(!handleException(ex) && mDefaultHandler != null){
mDefaultHandler.uncaughtException(thread, ex);
Thread.sleep(2000);
}catch (InterruptedException e){
Log.e(TAG, "error : ", e);
Intent intent = new Intent(application.getApplicationContext(), MainActivity.class);
PendingIntent restartIntent = PendingIntent.getActivity(
application.getApplicationContext(), 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
AlarmManager mgr = (AlarmManager)application.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000,
restartIntent);
application.finishActivity();
* 自定义错误处理,收集错误信息 发送错误报告等操作均在此完成.
* true:如果处理了该异常信息;否则没有处理返回false.
private boolean handleException(Throwable ex) {
if (ex == null) {
return false;
new Thread(){
public void run() {
Looper.prepare();
Toast.makeText(application.getApplicationContext(), "很抱歉,程序出现异常,即将退出.",
Toast.LENGTH_SHORT).show();
Looper.loop();
}.start();
return true;
二、通过在android Application 这个全局类中处理异常,一般我们都会重写一个我们自己的Application继承Application。
import android.app.A
import android.app.A
import java.util.ArrayL
* Created by willkong on .
public class MyApplication extends Application {
ArrayList&Activity& list = new ArrayList&Activity&();
public void onCreate() {
super.onCreate();
UnCeHandler catchExcep = new UnCeHandler(this);
Thread.setDefaultUncaughtExceptionHandler(catchExcep);
* Activity关闭时,删除Activity列表中的Activity对象*/
public void removeActivity(Activity a){
list.remove(a);
* 向Activity列表中添加Activity对象*/
public void addActivity(Activity a){
list.add(a);
* 关闭Activity列表中的所有Activity*/
public void finishActivity(){
for (Activity activity : list) {
if (null != activity) {
activity.finish();
android.os.Process.killProcess(android.os.Process.myPid());
人为的制造一个异常
import android.support.v7.app.AppCompatA
import android.os.B
import android.view.V
import android.widget.B
import android.widget.TextV
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private MyApp
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button)findViewById(R.id.btn);
tv = (TextView)findViewById(R.id.tv);
application = (MyApplication) getApplication();
application.addActivity(this);
btn.setOnClickListener(this);
* 人为制造的异常*/
public void press(){
new Thread(new Runnable() {
public void run() {
tv.setText("dfsd");
}).start();
public void onClick(View v) {
&?xml version="1.0" encoding="utf-8"?&
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.testapplication.MainActivity"&
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" /&
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content" /&
通用 application
1、收集所有 avtivity 用于彻底退出应用
2、捕获崩溃异常,保存错误日志,并重启应用
public class HKBaseApplication extends Application {
private List&Activity& activityL
protected boolean isNeedCaughtExeption = true;
private PendingIntent restartI
private MyUncaughtExceptionHandler uncaughtExceptionH
private String packgeN
public void onCreate() {
super.onCreate();
activityList = new ArrayList&Activity&();
packgeName = getPackageName();
if (isNeedCaughtExeption) {
cauchException();
private void cauchException() {
Intent intent = new Intent();
intent.setClassName(packgeName, packgeName + ".LoginActivity");
restartIntent = PendingIntent.getActivity(getApplicationContext(), -1, intent,
Intent.FLAG_ACTIVITY_NEW_TASK);
uncaughtExceptionHandler = new MyUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(uncaughtExceptionHandler);
private class MyUncaughtExceptionHandler implements UncaughtExceptionHandler {
public void uncaughtException(Thread thread, Throwable ex) {
saveCatchInfo2File(ex);
AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, restartIntent);
finishAllActivity();
finishProgram();
* 保存错误信息到文件中
* 返回文件名称
private String saveCatchInfo2File(Throwable ex) {
Writer writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
Throwable cause = ex.getCause();
while (cause != null) {
cause.printStackTrace(printWriter);
cause = cause.getCause();
printWriter.close();
String sb = writer.toString();
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
String time = formatter.format(new Date());
String fileName = time + ".txt";
System.out.println("fileName:" + fileName);
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
String filePath = Environment.getExternalStorageDirectory() + "/HKDownload/" + packgeName
+ "/crash/";
File dir = new File(filePath);
if (!dir.exists()) {
if (!dir.mkdirs()) {
return "";
System.out.println("filePath + fileName:" + filePath + fileName);
FileOutputStream fos = new FileOutputStream(filePath + fileName);
fos.write(sb.getBytes());
fos.close();
return fileN
} catch (Exception e) {
System.out.println("an error occured while writing file..." + e.getMessage());
return null;
public void removeActivity(Activity activity) {
activityList.remove(activity);
public void addActivity(Activity activity) {
activityList.add(activity);
public void finishAllActivity() {
for (Activity activity : activityList) {
if (null != activity) {
activity.finish();
public void finishProgram() {
android.os.Process.killProcess(android.os.Process.myPid());
异常捕获 简单用法介绍:
public class MyApplication extends Application implements
Thread.UncaughtExceptionHandler {
public void onCreate() {
super.onCreate();
Thread.setDefaultUncaughtExceptionHandler(this);
public void uncaughtException(Thread thread, Throwable ex) {
System.out.println("uncaughtException");
System.exit(0);
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
以上的尝试方法都没有成功,下面的一种方式成功了。
步骤一、在你自己的Application类的onCreate()方法下 加入代码捕获异常,并且处理异常。Thread.setDefaultUncaughtExceptionHandler(restartHandler); // 程序崩溃时触发线程
以下用来捕获程序崩溃异常
public void onCreate() {
super.onCreate();
Thread.setDefaultUncaughtExceptionHandler(restartHandler);
步骤二、 编写方法创建服务用于捕获崩溃异常并且处理
private UncaughtExceptionHandler restartHandler = new UncaughtExceptionHandler() {
public void uncaughtException(Thread thread, Throwable ex) {
restartApp();
public void restartApp(){
Intent intent = new Intent(this,MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);
android.os.Process.killProcess(android.os.Process.myPid());
成功解决问题。酷派大神f2怎样隐藏应用程序图标,。。_百度知道
酷派大神f2怎样隐藏应用程序图标,。。
我有更好的答案
打开应用界面点击菜单键---隐藏应用程序--选择你要隐藏的程序。
么有菜单键
菜单键就是下面的
隐藏这个字
难道你的难道你的系统不一样??
点桌面设置 切换回经典桌面 轻桌面不支持图标隐藏
亲,我的回答满意吧。给个好评吧,望采纳
采纳率:37%
按住图标五秒出现红色叉叉点击就可以了
我也是大神手机按住屏幕五秒会出现另一个窗口把图标拖进去就隐藏了
按住菜单屏幕
1条折叠回答
为您推荐:
其他类似问题
您可能关注的内容
应用程序图标的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。本文已收录于以下专栏:
他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)酷派大神f2怎么样隐藏应用程序图标,。。
打开应用界面点击菜单键---隐藏应用程序--选择你要隐藏的程序。
按住图标五秒出现红色叉叉点击就可以了
先排除系统软件问题并重启系统,如果还有此问题建议去维修点查看是否硬件问题,如果偶尔出现这类问题,可参考方法:1.恢复出厂设置或者双清数据可以解决此类问题:(1)关机状态下同时长按手机电源键、音量+这两个键。(2)屏幕亮后松开按键,等待进入恢复模式。(3)使用音量+和音量—键调整亮条至“wipe data/factory reset”即“清除数据恢复工厂设置”,按电源键确认。(4)使用音量+和音量—键调整亮条至“Yes,delete all user data”,按电源键确认。(5)等待一段时间至出现一下画面,选择“reboot system now”重启手机,按电源键确认。(6)等待手机重启进入系统。2.刷机能彻底解决问题;3.如果以上方法都无效,建议送售后。
可以尝试开启C键看。
一般都是一个小程序,点击一下锁屏的
人的综合分
感谢您为社区的和谐贡献力量请选择举报类型
经过核实后将会做出处理感谢您为社区和谐做出贡献
确定要取消此次报名,退出该活动?

我要回帖

更多关于 酷派大神f1 的文章

 

随机推荐