Kill an app process from the library project

206 views Asked by At

I am developing an Android library project which can be integrated to an app via a gradle dependency.

As a requirement I need to kill the app process from inside the library project.

I am using the following code to do that. But what I have noticed is that it kills the library project process but not the app process.

android.os.Process.killProcess(android.os.Process.myPid());

Any way or ways for achieving this?

EDIT: This has to be done at the library project level. Not from the client app level.

1

There are 1 answers

4
suhas sasuke On

Create a Service class in main app.

public class MyService extends Service{
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
         someMethod();
         return START_STICKY;
    }
    public void someMethod(){
      android.os.Process.killProcess(android.os.Process.myPid());
    }
}

and in your lib class use this.

Intent intent = new Intent(this, Class.forName("my service class path"));
startService(intent);

This will solve your problem.