(Sorry if I'm butchering any terminology- I'm still getting the hang of Android development. Please feel free to point out my mistakes)
I'm working on a project using several Service objects which appear as separate processes which appear under the Devices window in Eclipse's DDMS perspective. In order to step through one of these, I select its row, and click on the little bug icon (its tooltip is "Debug the selected process, provided its source project is present and open in the workspace").
I'm trying to debug one of these services' instantiation code. That doesn't allow me the needed time to perform those two mouse clicks, so my pre-set breakpoints won't pause the execution where I need.
In desperation I've tried using Thread.sleep() in the Service's onCreate() method, but it's only somewhat helpful, and a nasty habit I'd rather not develop.
What's the right way to debug this sort of code?
Thanks for you help!
Place a breakpoint at the earliest point possible in the main process (perhaps the first activity or a service that runs at startup).
Right click the breakpoint --> Breakpoint Properties... --> choose 'Suspend VM'
Run your app in debug mode (F11). When it reaches the breakpoint it should halt everything else, giving you the time needed to click the debug icon on the process you want.
Related
I am making an android app on API 15 for a mobile computer application.
In this app I have a background service, a lot of classes inheriting from AsyncTask, and some sql updates and broadcasting to the service on the app pausing.
I have recently discovered an issue where going to a specific screen in my app, hitting the home button, bringing up my app list, and swiping away my app to kill it results in the app closing and then soon restarting itself at the main activity. It should just close normally.
I have tried placing breakpoints everywhere, and even disabling the background service, but i cannot seem to find any indication of what is restarting the app when it is closed.
I just tried getReferrer inside a try catch and my app says it isnt responding and shuts down even though its in a try catch block.
Both problem seem odd to me.
If it means anything, Android studio will still be debugging the app once it has opened again after i close it.
If anyone could shed some light on what could be restarting my app after i close it, it would be very helpful.
EDIT:
I am using Start_Not_Sticky. this and Start_Redeliver_Intent are ideal option from what i have read.
Thank you to Kevin Krumwiede for suggesting grepping all my code for the main activity's name. I had no idea I could go through all of the code in my project within the IDE instead of going one file at a time.
I had previously tried going through all my classes and searching each individually for reference to it with ctrl+f but i never considered looking in one of my activities that i hadn't modified in months for the new issue.
when I used ctrl+shift+f it all came together as i saw the startActivity function inside of OnDestroy(), not sure how i never noticed this issue before.
Recently I noticed one thing in my app.
I created apk for my app say ABC.apk and copied to my device and installed it by clicking on it. After the installation got successfully completed, I got 2 options 'Done' and 'Open', the usual options we get after installation.
I clicked on 'Open' and run the app. I moved to some screen and I minimized the app and moved to someother app, when I click my ABC, it started from my first screen.
It was just fraction of seconds I moved back to it, hence it should not be killed though launched it like it is first time.
Few things I noticed I if I explicitly killed this first instance from background running apps and start the app again it is not giving me this problem, same if I click 'Done' instead of 'Open' it works fine.
Is there anyone who are facing same issue, or have some solution for it?
Thanks in advance.
Prajakta
The problem is the way that the app gets launched from the installer doesn't exactly match the way Android launches apps from the HOME screen. Because this, if you initially launch your app from the installer, when you then later launch the app again from the HOME screen, Android doesn't recognize that the app is already running and just creates a new instance of the root Activity and adds it to the existing task on top of whatever activities are already there.
This is why, if you kill the app and start it again from the HOME screen, you won't ever see this strange behaviour.
This is a nasty Android bug which has been around since the dawn of time and is still broken, even though countless issues have been opened about it and the behaviour is reproducible and well-documented.
See the following issues and questions:
https://issuetracker.google.com/issues/36941942
https://issuetracker.google.com/issues/36907463
https://issuetracker.google.com/issues/64108432
App restarts rather than resumes
Re-launch of Activity on Home button, but...only the first time
There is a workaround documented in my answer to
Re-launch of Activity on Home button, but...only the first time
Just some general comments that come to mind that you must consider that can cause problems.
If you are trying to deploy an apk, did you switch from debug to release before building it? Make sure you are doing a full release. Do a clean and rebuild while in release mode as well.
Did you sign the apk?
Make sure all the necessary (if any) permissions are set in the manifest that will be needed by your app, on the device.
Hope these help point you in a direction.
Mike
This is a follow up question to this previously asked question:
Eclipse ADT: Working but "Terminate" button greyed out...?
Like in the question above, the terminate button in Eclipse is grayed out, so like the answer is saying, I'm choosing the debug perspective, choosing the app name and then the button is enabled and I can terminate the session.
The problem is that this proccess repeats itself all the time. The button keeps graying out every time I open the debug and I have to repeat the above proccess every single time. Is there a way to fix it?
You can add the Devices view to your perspective - and then you don't need to change to the Debug perspective. To add it, go to Window -> show View -> Devices
I have been using Robotium for the last couple weeks writing test cases for an app. It's a great tool but there is one thing that I cannot seem to get working. The app I'm using creates a pop-up window regardless if you are in the app or not to notify the user and when looking at the UI Automator Viewer is is still tied to the same package that I am testing.
The issue is that I cannot read any text or click on anything in the window through Robotium. I created a test to see if Robotium can even see it going through all of the views in debug mode by hand but it seems to be transparent to it. Does anyone know a way around this or another program that would be ideal for this?
I'm building an app that is comprised of multiple APKs and I'm curious if it's possible to set up the debugger to follow along as one app invokes the next.
Is there such a feature? Or am I totally out of debugging luck on that front?
Use the DDMS perspective, there 'Devices' you follow each process emulator. So if your appA opening a second appB, this appears there as another process, just click on this to display your LogCat. And you can go alternating between them.