Debug android app when it starts on device - java

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?

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.

How does TeamExtreme MC launcher bypass auth?

I am developing a custom game launcher and as I was looking on how to launch minecraft 1.7.4 it seemed to me that the *.jar cannot be launched without setting an authentication process to the mojang site. However, TeamExtreme minecraft launcher bypasses this. How?
Most likely, it just sends in false data, or empty data. This should allow minecraft to launch in offline mode, meaning that it lets you join but you are not logged in, so that you cannot play on servers.
I am not entirely sure, however, this should send you on the right track.

How to debug an Android Background Service?

I have been developing a PhoneGap application for Android which contains a Background Service. My question is: How can I debug this service? Is it possible to debug using an AVD and go step by step? or can I use my own device to achieve that?
Thanks!
Yes, it can be done using AVD or device. Check out http://www.helloandroid.com/tutorials/how-debug-service and Debugging a service.
You can debug your service by putting a single statement , I am mentioning it here :
#Override
public void onCreate() {
super.onCreate();
//whatever else you have to to here...
android.os.Debug.waitForDebugger(); // this line is key
}
You can use your usual logs -for not in-depth debugging- inside the service and then use monitor tool to view those logs when the app is in the background or closed.
To open the monitor tool:
Open SDK( your SDK folder ) >tools>lib>monitor-x86_64
Open your monitor tool and select a device and you can view the loggings and search by tag as you do in your usual debugger.
Specific to intellij Idea, although there may be an equivalent solution for eclipse also,
I am adding a few more points to Shishupal's answer which worked for me, We need to add android.os.Debug.waitForDebugger(); in the service code.
But along with above, we need to uncheck "Deploy Application"
and select "Do not launch Activity".
In version 12.1.4 it looks like this:
Look for where your background service starts, for example
public BGcheckService() {
Log.d("BGcheckService: ", "starting service");
}
Then insert one line:
public BGcheckService() {
android.os.Debug.waitForDebugger();
Log.d("BGcheckService: ", "starting service");
}
Besides this, if your background service is in a separate process, then when you press the debug button to start debugging your background service, you also need to wait till the background service has started, then press the button to attach to process (see screenshot for Android Studio 3.6.1 .. it is the 3rd button to the right from the debug button). You will be given a choice of processes to attach to, one of which would be the background service's separate process.
NB:
Without the line android.os.Debug.waitForDebugger();, the background service would just start without waiting for the debugger to attach.
Even with the line android.os.Debug.waitForDebugger();, you still need to attach the debugger to the process of the background service.
The timing of when you press the button to attach to the process, needs to be after the background service has started (while it is waiting at android.os.Debug.waitForDebugger();), otherwise the process would not exist and you would not be able to select it.

Android bindService fails on 4.0.4 when device is unplugged from development PC

I have two devices (Samsung Galaxy Tab 10 running 4.0.4 and Nexus 7 running 4.2.1). My application i am writing uses bindService/unbindService a service written within the same application to handle the constant managing of data regardless of activity state. Emulator/devices connected to the PC with USB debugging enabled work as expected. As soon as i unplug the the devices and try to the run the application stand-alone it doesn't error or exit or anything just doesn't bind so my log-in button doesn't work in my application until the bind is complete. This bind never completes and I have no idea why. Has anyone else experienced this?
I am including this for anyone who may run into this situation in the future. In my situation this was failing because the background service was waiting for a debugger thanks to android.os.waitForDebugger() and it was timing out. One line can screw your world up.. I had completely forgot that was in there.

Categories