O
O
Oleg Gamega2014-07-07 17:24:05
Android
Oleg Gamega, 2014-07-07 17:24:05

Unkillable Activity, how to implement?

Good day.
How to make an activity that cannot be closed. The device is used as a measuring device, the user must not access other functions.
I check if the activity is running in the service and if not, I launch it, but on some phones, after pressing the home button, you can get into the dialer, on some, in the settings and at the same time, the activity is not being restored

while (!Setting.getPassword(getApplicationContext()).equals(CryptoUtil.getHash(Setting.SALT1 + Setting.pseudoID+Setting.SALT2) )){
                    AudioManager aManager = (AudioManager) getSystemService(AUDIO_SERVICE);
                    aManager.setRingerMode(aManager.RINGER_MODE_SILENT);
                    if (!isRunning(getApplication())) {
                        Intent dialogIntent = new Intent(getBaseContext(), MyActivity.class);
                        dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        getApplication().startActivity(dialogIntent);
                    }
                }

public boolean isRunning(Context ctx) {
            ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
            List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

            for (ActivityManager.RunningTaskInfo task : tasks) {
                if (ctx.getPackageName().equalsIgnoreCase(task.baseActivity.getPackageName()))
                    return true;
            }

            return false;
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pi314, 2014-07-07
@gadfi

In principle, in addition to those indicated, there are still a lot of ways to kill or at least hide the activity. Even the on-screen keyboard (not to mention the camera, screensaver, etc.) sometimes allows you to go into the settings with all the consequences :)
The only complete solution to the problem is to build your own firmware.
Well, from the cheaper, but still angry ones: make your own launcher or control the presence of a taskbar (stupidly kill the process when it is not needed) from your application ... however, this requires root.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question