0

i set a service that checks if a specific process is running in time intervals by using:

appsList = am.getRunningAppProcesses();

i saved its name and id with:

s = pross.processName;
i=pross.pid;

i launch the default launcher with:

Intent intent = null;
        final PackageManager pManager = context.getPackageManager();
        for (final ResolveInfo resolveInfo:pManager.queryIntentActivities(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME),pManager.MATCH_DEFAULT_ONLY ))
        {
            if(!context.getPackageName().equals(resolveInfo.activityInfo.packageName))
            {
                intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
                break;
            }
        }
        context.startActivity(intent);

than kill the process with :

mActivityManager.killBackgroundProcesses(s);

it all works fine but the problem is that its doing the whole calling the launcher and closing the process twice. it's like the process is still running the second time the service checks if its running.

any idea how to solve this?

  • You should not be doing this to begin with as it is a design pattern inconsistent with Android, where the system, not a 3rd party developer, manages process lifetime. – Chris Stratton Mar 03 '14 at 12:33
  • i know. but it is vital to my app – Aviad Lidani Mar 03 '14 at 18:52
  • Why is it vital? Why do you think you should do something that causes Android to start a process (if it doesn't already exist), then turn around and kill it? Anyway, no one can really help as you've given two isolated pieces of code with no sense of the program which connects them. – Chris Stratton Mar 03 '14 at 19:21

1 Answers1

0

I think we can not kill any other process. System not allow to do that without root access.

Ankit
  • 256
  • 1
  • 9