While developing I wanted to test the situation where the system kills a service. This is because I'm loosing connection when communicating between the Android Wear and the handheld. And I think that it is related with the system killing some services.
Does anyone have a suggestion on how to approach this?
if you're developing in Android Studio while you are running your application in android wear side try to hit the kill button displayed in the console.
When you hit this button all the threads + services + activities from this app will be destroyed. If your service is of type "STICKY" it will start by itself after you kill your application.
As of 2020 we have to do it manually (since we don't have Android Monitor or DDMS anymore).
This was tested on Linux. You need root permission for the device (how to get root for an AVD).
Getting the PID (first number): adb shell ps | grep -i <package-or-part-of-it>
Killing the process: adb shell kill <your-PID>
cdlc's answer works, but another way is if you're developing in Android Studio you can go to DDMS: Tools->Android->Android Device Monitor and press the stop button there and you will also see a sticky service restart.
If you check the developer options on an Android phone, there will be an option to show the running services. Under that option you can choose to stop any service that is running.
Related
I'm developing an android app which will display list of all the installed app in mobile.
I'm already listed all the app which are installed in my phone, and trying to stop a app from list.
I want to stop a app from list by one click. Without Root
Thanks in advance.
You can only kill your own apps, for example, the apps which are running in the same process or with the same userID. You can not kill others, unless the device is rooted.
Look at this answer to know about killing background processes of app.
I am using keymapper to try to map a button to kill recent apps because I can open the shelf but not close them with my remote.
I have thought a simple alt f4 would do the trick unfortunately the application does not have keyboard shortcuts.
I was hoping there is a shell command that I could map to a key which will kill all recent apps.
Any help would be appreciated.
I've tried pressing all the keys on my remote and remapping long presses but I can not find an option to remap either mouse or keyboard input to my remote
am kill recent
app recent not found
(edit i have the start.ca IPBS9510 running 8.0 / 5 July 2018 Kernel 4.9.61 inspur#s99 #1 Build OPR6.170623.013.1.1.0 release-keys)
i dont think am kill recent will work, unless your package name is "recent".
the correct command usgae should be like this:
am kill <package>
am kill-all
am kill: Kill all processes associated with . Only kills.
processes that are safe to kill -- that is, will not impact the user
experience.
am kill-all: Kill all background processes.
P.s: get the list of current active process, then traverse it to get the package name.
I have an app which runs a background service overnight. It's triggered to run by an alarm clock app.
The app spends the night uploading data off the phone's external SD card onto Dropbox. It worked seamlessly on previous versions of Android but is not working on Pie. The background service is killed after running for about two hours every night. Interestingly, however, I've noticed that if I make a tiny change to my code, e.g. editing a string, and then run a debug, the app runs perfectly the next night but then on subsequent nights, goes back to being killed after two hours.
I've tried the following:
Using a foreground service with a persistent notification
Opening and closing an Activity after the app is opened so it's in the recent apps list
Making the app a device administrator
Disabling battery optimisations for the app
CPU and Wifi wakelocks
Running a thread with an infinite loop that uses root privileges to adjust the app's minfree values every five seconds
Disabling Pie's adaptive battery manager feature during the night
Despite all of these mechanisms, the app still gets killed. My theory is that there's some kind of artificial intelligent battery manager/performance optimiser on the phone that picks up that the app runs all night and decides to kill it in the future but then gets reset when I re-install the app.
I've tried everything and I still can't seem to find a solution. Can someone please point me in the right direction? I'm sure there's some root/reflection thing that I can do to fix this but I just don't know what it is!
I found the problem! Turns out my phone had a service called G3 which was killing the app to "save power". Apparently, this service is useless so I uninstalled it and the problem was solved instantly!
I used the following command:
adb shell pm uninstall --user 0 com.evenwell.powersaving.g3
adb shell pm uninstall --user 0 com.evenwell.powersaving.g3.overlay.base.s600ww
Pretty annoyed that this service took to killing an app that had root, administrator privileges and permission to avoid battery optimisations - how obvious do I have to make it that I want the app to stay alive?!
try job schedular
https://developer.android.com/reference/android/app/job/JobScheduler.html
https://developer.android.com/topic/performance/scheduling.html
use Alarm manager
https://developer.android.com/reference/android/app/AlarmManager.html
As one of the changes that Android 8.0 (API level 26) introduces to improve battery life, when your app enters the cached state, with no active components, the system releases any wakelocks that the app holds.
In addition, to improve device performance, the system limits certain behaviors by apps that are not running in the foreground. Specifically:
Apps that are running in the background now have limits on how freely they can access background services.
Apps cannot use their manifests to register for most implicit broadcasts (that is, broadcasts that are not targeted specifically at the app).
By default, these restrictions only apply to apps that target O. However, users can enable these restrictions for any app from the Settings screen, even if the app has not targetted O.
Nothing will work like job schedular or Alarm manager
Your problem will be only resolved by using WorkManager
I have developed and android application which is called after phone boot is completed. Now, for testing it I am using my android phone and every time I have to switch on and off my phone to test it.
Is there any command on for android emulator which switch offs and switch on it. I want to test it on android emulator. Let me know how can I do it.
I wrote such a boot service. Just close the emulator window, and reopen it to test the boot service.
But it's tricky: When you start the emulator window again, be carefull not to use the run button. If you use the run button, the application will be installed again, and the boot service is not active right after installation.
So you need to install the application, close the emulator, and then to open the emulator using the green button in the toolbar. If you can't find this button, just start any other Android project.
Your boot service will now be executed.
I am trying to launch the Main Activity from a broadcast receiver. Can anyone guide me as to how I can do it? I always get "Process is Bad" message.
Thanks
Restart the emulator or just Kill the process that will solve this situation.
When using a real device, the only I found to fix this was:
Uninstall the app through Settings -> Applications.
Remove the battery from the phone (using the Android "Power off" menu did not work).
Turn device on again.
Install the APK again using adb install .
My app didn't show up in the list of processes running on the device (it's a BroadcastReceiver), so I wasn't able to kill that process.
See my answer here for more detail on what didn't work.