Back to project page android-utils.
The source code is released under:
Apache License
If you think the Android project android-utils listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * Copyright 2014 Zhenguo Jin (jinzhenguo1990@gmail.com) *//from ww w . j a va 2 s. co m * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.worthed.app; import java.lang.Thread.UncaughtExceptionHandler; import java.util.Calendar; import java.util.GregorianCalendar; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Looper; import android.text.TextUtils; import android.widget.Toast; /** * ????????????????????????????????????????????????????? * <br>??????????????AndroidMainfest.xml???me.xiaopan.android.content.StartApplicationBrocastReceiver?????????????filter? * <br>????????Application?onCreate()?????new RebootThreadExceptionHandler(getBaseContext());?????? * * @author zhenguo */ public class RebootThreadExceptionHandler implements UncaughtExceptionHandler { private Context context; private String hintText; public RebootThreadExceptionHandler(Context context, String hintText) { this.context = context; this.hintText = hintText; Thread.setDefaultUncaughtExceptionHandler(this); } public RebootThreadExceptionHandler(Context context) { this(context, null); } @Override public void uncaughtException(Thread thread, Throwable ex) { ex.printStackTrace();// ?????????????? if (TextUtils.isEmpty(hintText)) { /* ???????????????? */ new Thread(new Runnable() { @Override public void run() { Looper.prepare(); Toast.makeText(context, hintText, Toast.LENGTH_SHORT) .show(); Looper.loop(); } }).start(); /* ?????1?????????????????? */ try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } /* ???????1??????????????????? */ AlarmManager alarmManager = (AlarmManager) context .getSystemService(Context.ALARM_SERVICE); Calendar calendar = new GregorianCalendar(); calendar.add(Calendar.SECOND, 1); alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), PendingIntent.getBroadcast(context, 0, new Intent(context, StartAppReceiver.class), 0)); android.os.Process.killProcess(android.os.Process.myPid()); // ??????? } }