Does rerunning your application in android studio restart services? - java

I'm building an android app. It includes an intent service to do some background work. Does rerunning the app from android studio (on a phone) also restart the service? In other words, can I be sure to be using the most recent version of the service?

Put a printout in. It came up. The answer is thus: Yes

Does rerunning the app from android studio (on a phone) also restart the service?
So far I have observed that AS builds a new apk and installs it to the device everytime a Run command is issued. That means killing all processes of your app, replacing the apk (that includes activating receivers, content provider) and starting main activity.
In Eclipse when no changes were made only the main activity was started.
In other words, can I be sure to be using the most recent version of the service?
Yes, you can.

Related

How to hard close/force close/kill the app from memory in Android using Appium in the same test

This is my scenario
Launch the app and perform some steps
Hardclose/Forceclose/Kill the app from memory/Should not run in background
Launch the app again
Perform some steps
Assertion step
How to achieve this?
I have tried the following methods
resetApp() - it uninstall the app and install app again.
closeApp() - it just close the app but app is still running in the background.
adb shell am force-stop <packagename> - it just close the app but app is still running in the background.
But for my scenario it should delete from the background and app should not uninstall in Android in the same test (middle of the test).
You can try it, I think it will serve your purpose, use below line from where you want to launch the app again
Activity activity = new Activity("appPackage", "appActivity");
driver.startActivity(activity);
Try below code and add this to the capability :
capabilities.setCapability(MobileCapabilityType.NO_RESET,"false");
It should work as per your requirements.

Uninstalling addons when main app is uninstalled

I want to create an add-on for an app, which the user can download from the Play store separately, and it will function with the aforementioned app that i've created.
I am using service, as this is the only clean way that I've come across for this. It works well with the "Base App" which I've created but I have no way of having it get removed when the user uninstalls the "Base App". I do know that i can essentially "Throw a dialog" up if the user attempts to uninstall my app, but i feel that has a more malicious feeling to it than what I intend. I don't want to interfere with the uninstalling of my app, simply I want to have the secondary addon service be uninstalled too.
You can listen to the broadcast to see if your main app is being uninstalled. See this for more info:
Android: Listen for app installed / upgraded broadcast message
When you detect that your main app is removed, your add-on app can suggest/remind users to uninstall add-on app using Android notification.

When Android Service code in a Google Play app will be updated?

I have an Android app published on Google Play. When the app is launched for the first time (it is done by storing and checking boolean flag "FirstLaunch" in SharedPreferences), it launches a Service which will be launched once a day (=every 24 hours using AlarmManager).
For the sake of simplicity let's say that this service just shows a Toast with "Hello World!" when the time comes.
Let's assume that there is a user who downloaded and installed my app from Google Play.Let's also assume that I have changed some code in that service (e.g. changed the Toast from "Hello World" to "Hello Universe!") and updated the app on Google Play.
If that user updates my app, will the service start showing new Toast text ("Hello Universe") once a day, or will it still show the old version ("Hello World")?
Generally speaking, if I am changing the code of a running service, do I need to relaunch it programmatically in my app, or will Android itselft change/switch its code to the new version?
Android services runs as part of your application process, when the process is terminated your services will be terminated as well (it will be restarted if its start mode is sticky which will restart the whole process), so when the user updates your app a new process will be started with your new code
If Android updates an app (through the PlayStore of course),which you are currently using, it gets terminated. Services get terminated as well. So if users of your app receive their update, their service gets terminated and restarted, if thestartmodeof your service issticky or it gets restarted by your app.

Debug android app when it starts on device

I have an android app that is opened by a URL on my website. What I am looking to do is, attach Eclipse in debug mode when the app starts. I can start the app in debug mode from Eclipse, but I do not know how to get Eclipse to start when the user/another app starts the app on the device.
Add a call to android.os.Debug.waitforDebugger() on the onCreate of your launch activity. This will make you app wait for a debug to attach whenever it is launched.
If you look in detail, there's a moment when Eclipse tries to couple the runtime session with the debugger so it starts listening to it until the coupling is made. I guess you'll need to trigger that whenever you open your app.
My question would be, why do you need that? Which are the different conditions when you start the app from the web that make it necessary to debug from there? If there are some, is there any possibility to fake them with any constants or db data?

Android 2.3X kills Apps into the Background

I always used Android 2.2 for my Apps. But currently I upgraded to Android 2.3.X Gingerbread. So if I start my App and go back to the android "desktop", the app is kill by 3-4 Minutes.
I think it will be killed after some minutes inactivity, but I need to run it in background to read some mobile status.
How can I set my App as a "Background" App, so that Android will not longer kill it?
Thanks for Help...
Regards, Rookee
To run an application in the background it must be of type "Service". You have to register a service and it will run in your device forever. For more info, Android Services

Categories