I am developing an application which is used as application locker, an app which is able to protect other installed apps by asking the user for a password on opening those a
Create your own Exception Handler & whenever app crashes start service ..
Your Exception Handler Class
*public class MyHandler implements UncaughtExceptionHandler {
private Context m_context;
public static void attach(Context context) {
Thread.setDefaultUncaughtExceptionHandler(
new MyHandler(context)
);
}
///////////////////////////////////////////// implementation
private MyHandler(Context context) {
m_context=context;
}
public void uncaughtException(Thread thread,Throwable exception) {
/* StringWriter stackTrace=new StringWriter();
exception.printStackTrace(new PrintWriter(stackTrace));*/
System.out.println("ERROR IS "+(exception));
Intent intent=new Intent("com.sample.service.serviceClass");
m_context.startService(intent);
// from RuntimeInit.crash()
Process.killProcess(Process.myPid());
System.exit(10);
}
}*
Attach In Your Activity
public class MyActivity extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grid_layout);
MyHandler.attach(this);
}
}