I am trying to create an application that, when the phone receives an incoming SMS, reads its contents plus the number and writes it into its database . The application receives SMS information via the BroadcastReceiver , working in the background.

The following is required: the application should recover after the system kills it due to lack of resources.

How to implement it?

    1 answer 1

    Add your main activity to onCreate:

     intent = PendingIntent.getActivity(YourApplication.getInstance().getBaseContext(), 0, new Intent(getIntent()), getIntent().getFlags()); 

    And in uncaughtException()

     AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 2000, intent); System.exit(2); 
    • Thank you very much, I did not even know about PendingIntent until this moment. But with ALARM_SERVICE such an idea was, it just seemed to be a crutch at first and thought to hold it in an emergency, if there was no other way. I will implement. - Ernest Denisov