How to kill a non-running process on Android

Has anyone encountered this situation before? I force the application to stop in the settings dialog on the Android device. But when I use the ps command through adb , it still appears on the screen. But this process cannot get activityManager.getRunningAppProcesses() . This process exists even after uninstalling this application. This happened by accident.

Since I opened the port in my application using ServerSocket , the port cannot be released after stopping my application. The next time I tried to open my application, it again could not use this port.

I use ASUS EeePad, and this problem only occurs on this device.

By the way, a process cannot be obtained by any third-party tools, such as a process manager. But it really exists with pid , when I use ps via adb shell to list all processes.

+7
source share
1 answer

Since there is no code ... here are some tips:

1 - do you close your connection ??? this will be the main reason that the port is busy.

2 it is safer to work with the socket when your application is stopped, stopped or destroyed .. you can override onpause, onstop or ondesotry .. and free the port before closing the application.

3- make the connection in a separate thread and implement a timer to check whether you really need a port or not (I mean, if your application is live or not) and based on this kill / leave the stream (connection)

4- in the worst case. If you have control over the other side of the connection (server, device ..), try to make your solution more flexible, for example, first determine the range of ports, and then use if available.

luck

0
source

All Articles