Skip to content

Instantly share code, notes, and snippets.

@teopeurt
Created March 23, 2012 17:34
Show Gist options
  • Save teopeurt/2173050 to your computer and use it in GitHub Desktop.
Save teopeurt/2173050 to your computer and use it in GitHub Desktop.
Suppressing ANR, auto-restarting app. Not recommended for Google Market!
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);
}
});
}}
@teopeurt
Copy link
Author

Note that with RTC_WAKEUP, the tablet wakes up if in sleep mode!,

Replace all your base activity with this base activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment