Created
March 23, 2012 17:34
-
-
Save teopeurt/2173050 to your computer and use it in GitHub Desktop.
Suppressing ANR, auto-restarting app. Not recommended for Google Market!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Activity; | |
import android.app.AlarmManager; | |
import android.app.PendingIntent; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.util.Log; | |
public class BaseActivity extends Activity { | |
PendingIntent intent; | |
Context context; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
intent = PendingIntent.getActivity(this.getBaseContext(), 0, new Intent(getIntent()), getIntent().getFlags()); | |
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { | |
@Override | |
public void uncaughtException(Thread paramThread, Throwable paramThrowable) { | |
AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); | |
mgr.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 120000, intent); | |
System.exit(2); | |
} | |
}); | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that with RTC_WAKEUP, the tablet wakes up if in sleep mode!,
Replace all your base activity with this base activity.