Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to obtain the PID with the class name and kill the process obtained
    primarykey
    data
    text
    <p>I'm trying to get the PID of a process having the class name. The idea is that the user will create a task, select the event, the app and if the app will be opened or killed, so if the user select killed, I want to map the class name in the <code>ComponentName</code> of the intent to the <code>ComponentName</code> in a <code>RunningAppProcessInfo</code>.</p> <p>The problem is that I'm getting a <code>NullPointerException</code>, and I really can't figure out why, it happens when I check the classname in the if - maybe I'm misunderstanding something... Any ideas?</p> <p>Note: I'm passing the context in order to have access to the ActivityManager</p> <pre><code>public static int getPid(Context ctx, Intent intent) { ActivityManager am = (ActivityManager)ctx.getSystemService(Context.ACTIVITY_SERVICE); int pid = 0; for(RunningAppProcessInfo a : am.getRunningAppProcesses()) { //Revisar TODO if(intent.getComponent().getClassName().equals(a.importanceReasonComponent.getClassName())) { pid = a.pid; break; } } return pid; } </code></pre> <p>Here is the logcat:</p> <pre><code>D/su ( 6479): 10106 com.android.test.tasker executing 0 /system/bin/sh using shell /system/bin/sh : sh D/AndroidRuntime( 6446): Shutting down VM W/dalvikvm( 6446): threadid=1: thread exiting with uncaught exception (group=0x40015560) E/AndroidRuntime( 6446): FATAL EXCEPTION: main E/AndroidRuntime( 6446): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.AIRPLANE_MODE flg=0x20000000 (has extras) } in com.android.test.tasker.events.AirplaneEvent@4051fee8 E/AndroidRuntime( 6446): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:722) E/AndroidRuntime( 6446): at android.os.Handler.handleCallback(Handler.java:587) E/AndroidRuntime( 6446): at android.os.Handler.dispatchMessage(Handler.java:92) E/AndroidRuntime( 6446): at android.os.Looper.loop(Looper.java:130) E/AndroidRuntime( 6446): at android.app.ActivityThread.main(ActivityThread.java:3835) E/AndroidRuntime( 6446): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 6446): at java.lang.reflect.Method.invoke(Method.java:507) E/AndroidRuntime( 6446): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864) E/AndroidRuntime( 6446): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622) E/AndroidRuntime( 6446): at dalvik.system.NativeStart.main(Native Method) E/AndroidRuntime( 6446): Caused by: java.lang.NullPointerException E/AndroidRuntime( 6446): at com.android.test.tasker.util.Root.getPid(Root.java:97) E/AndroidRuntime( 6446): at com.android.test.tasker.events.GenericalEvent.openKill(GenericalEvent.java:35) E/AndroidRuntime( 6446): at com.android.test.tasker.events.AirplaneEvent.onReceive(AirplaneEvent.java:24) E/AndroidRuntime( 6446): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:709) E/AndroidRuntime( 6446): ... 9 more </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload