I am working on an application that will be installed in a custom android device (api 28, specs are irrelevant here i think)
I have root privileges and i can edit the android OS too if needed.
The application is a supervision UI interface that is connected to a remote server. it is the main launcher and the only application running on the device, the device itself is intended to be constantly on.
I have edited the os to limit the doze to dimmer turn off the screen light only after a certain amount of time and to never sleep, in this way my app keep receiving and processing the server messages realtime (as intended)
My issue here is how to handle the app crashes without the final user presence. It can happen, example, that the app exceed the amount of ram and android itself decide to kill my app (but can be any other reason not handled by me). In that case my app restart ONLY after the user wake up the device by touching the screen.
Is there a way to relaunch an app that has been killed by the system (and when the system is in an idle mode) without the user iteraction?
I tried different approaches but none worked, I think the closest one i get is this:
Intent mStartActivity = new Intent(getBaseContext(), DovitActivity.class);
int mPendingIntentId = 123456;
PendingIntent mPendingIntent = PendingIntent.getActivity(getBaseContext(), mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager)getBaseContext().getSystemService(Context.ALARM_SERVICE);
mgr.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 100, mPendingIntent);
Runtime.getRuntime().exit(0);
that in theory it should work, but still my app "waits" to start until an user wake up the screen.
thanks