1

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

1 Answers1

0

use android:persistent for you application.

This flag is only for system app. The OS will start the persistent app automataticly, and will restart it after the app is crashed. The persistent app will have a high priority, and it will not killed when low memory.

And you should make your persistent app stable, and avoid that the persitent app crashed, be started by OS, then crashed again, again.

Yong
  • 1,529
  • 12
  • 21
  • Thanks for the answer, i tried that too (and my app is a system app) but same result. The main issue as said is the app not starting until an user iteraction occurs. Without the bit of code i shared, (but even with, the result is the same) if i set the application as main launcher and i simulate a crash (by killing the app with adb) I see the app restarting (onCreate of the mainActivity has been called)… but if the device is in idle state, until the user wakeup it the app wont go further from its splash screen. Ah, maybe that helps: the application is built using unity. – Nicola Valcasara Feb 28 '22 at 12:17