How to debug android callbacks? - android

I am trying to use the Eclipse debugger to debug my Android application, but it doesn't seem to be working. I have a callback in my MasterActivity.java file for onOptionsItemSelected, and I set a breakpoint in this method at a point that I know is being hit. I then right click my application, and go to Debug As -> Android Application. When I click the button in the ActionBar that triggers this callback and should start the debugging process, my program just continues like my breakpoint is not there. I must be missing something basic here, but I'm not sure what.

Simon's suggestion to add a Log message is a good start to ensure that the callback is being called, unless there is already some other evidence unique to the callback that it is being triggered. We can only guess as you haven't included any code, and nothing wastes time like a programmer assuming they are correct, myself included ;-)
However, try adding a call to waitForDebugger() just prior to the line with the breakpoint active.

A good way to check if an item, in this case a menu item I guess, is to use the method Log.d(String tag, String message). So in your onOptionsItemSelected event handler, you can add e.g Log.d("Debug", "Options item is selected"). It isn't necessary to use Debug As, Run As will work too. The log message will be displayed in blue in the LogCat in Eclipse.

Related

How to view the line by line execution flow of app in android studio?

We can use debugger in android studio and set breakpoints for the lines we want to check but if i want to see what lines are being executed orderwise and skipping iterating through the lines of code of system classes like Activity.java, Fragment.java, Looper.java, Handler.java How can I do that.
Also I would not like to set the breakpoints and see the debugger going through the execution of the app and highlight the lines that are being executed as I launch the app and click buttons.
If I understand correctly what you need and don't want, you can use Logpoints instead of breakpoints. To do that, set breakpoints where you want to see if your code gets called. Then right-click on those break points and un-tick the suspend option. That will bring up a more extensive menu. From there you select "Log message to console". You execute your code and see all the logpoints accessed in your console.

Is it possible to check a second Espresso Intent matcher after you receive the result from the first one?

When using the intended(IntentMatcher) from the Android Espresso API, is it possible to do this twice in the same Activity?
So for example I click a button which starts an Activity for result. I check that this Activity has fired using intended(IntentMatcher). That works.
However, when I get the result, I want to fire off an Intent for a different Activity. In this case just a local Activity in the same app package with no result.
When I do this manually in the app it works fine, but Espresso can't seem to detect the second Intent in my test. What I am I missing or is this not possible? Alternatively, how should I be doing it? Maybe my design is bad.
When I do the check I'm trying this:
intended(toPackage(<packageName>));
intended(hasComponent(hasClassName(<className>)));
The first line matches but not the second one. And even if the second line is not completely correct it never seems to show anything in the error log about the second Activity I'm actually starting.
Another thing adding to the confusion is that two intents are definitely being fired as it shows that in the log. They both seem to be the same one but with slightly different details - one is a package, one is a component. Does it log the result from the first Intent as an Intent in itself? Sounds unlikely but where is this other intent coming from? I know it's not the second Activity I'm launching as it still fires even when that Activity isn't called (when the first Intent result is a fail).
I've also considered that maybe it's not getting detected because it's not waiting long enough for the second intent to fire. If that were the case, what would I do about that? I don't see much talk about handling time sensitive things in Espresso. Like checking if a progress bar is shown but then hidden again while not pressing anything. How do you do that? Maybe it's the same answer.
Any help appreciated!
Ok I found the problem. My IdlingResource wasn't working.
After fixing that it works like a charm :)

Android - problems with a multi-level activity chain

(Note that I've searched online for the warnings I'm describing below, and have come up with next to nothing about them.)
I'm working with API level 10. I have a preference screen (XML-based), and one of the options in there creates a custom ListActivity as follows:
PreferenceActivity contains an option that creates a...
ListActivity which is a dialog that employs...
setOnClickListener() which contains an onClick() method that (right before calling finish()) will startActivity() a new Intent...
sub-Activity which starts up an...
AsyncTask which does variable time work which when done calls...
onPostExecute() which calls finish()
The thing is, it works... but I'm getting a raft of warning starting with:
10-16 21:59:25.010: WARN/WindowManager(170): Rebuild removed 4 windows but added 3
10-16 21:59:25.010: WARN/WindowManager(170): This window was lost:.....
Curiously, this raft of warnings ONLY comes up when the task executes quickly! When I added a Thread.sleep() call to my AsyncTask to artificially inflate its runtime it worked and threw no warnings whatsoever. In fact, as long as it takes more than (roughly) 500 ms to run it works fine. (Note that I tried using startActivityForResult() to no greater effect - the same problem occurs.)
The goal is that the user selects a preference item, they change its setting, some processing takes place, and then the user is left back at the preference menu they started on.
I'm betting it's a race condition... the order in which the windows are destroyed varies depending on that run-time... and I get the impression that when the sub-Activity closes before its parent ListActivity the warnings get thrown. But sprinkling a 1s sleep() in isn't a reasonable solution unless this is some sort of Android bug (unlikely, but then again I've reproduced a couple of those today already).
So, what's the flaw in this my that leads to this stream of warnings? It'd be nice to say "on preference, do this, then do that, then finish" but I think what I'm doing is the equivalent. Maybe not... thoughts?
Edit: I decided to try doing this ListActivity as a custom Dialog... that was one of the more painful things I've tried to do lately (getApplication() doesn't work and lots of other things seem to go wrong... it may be inexperience to some extent, but dialogs really weren't meant for this either...
Try the following two things:
Dismiss your dialog before calling finish() on its parent activity (PreferenceActivity).
Make sure you are starting your AsyncTask later in the sub-activity's lifecycle. I'm specifically thinking you should launch it in onResume().
My best guess is that the AsyncTask is calling finish() on the sub-activity, before the sub-activity has had a chance to fully start up. Why that would matter? I'm not sure. Something to try though. Good luck!

Android onClick event fails

I'm having some problem here with android + java + cloud. My onCLick event is working only one time
The event only work again when i go back to the last screen and enter again in the screen that i made searchs in the cloud...
I think you are only allowed to call setContentView() once. Since you are doing it in your click listener that might be why it is failing after the first time.
Edit: What does it do when it fails? Force close? nothing? something unexpected?

ResourceNotFound on layout inflation

My app may launch a sub-activity for a specific purpose. When that activity finishes, I get the results in onActivityResult. These results are then processed in the subsequent onResume. This consists of a setContentView and also starting an AsyncTask that puts up a ProgressDialog.
This all works well when initiated the normal way, which is via a user request (i.e., menu selection) after the app is up and running. However, under some conditions I need to do this right as the app is starting up, so I initiate this sequence right from my onCreate. What then happens is that I get fatal ResourceNotFound errors within any o/s call that implicitly calls the layout inflater. I got around this with setContentView by pre-inflating the view in my onCreate method, but the AsyncTask's onPreExecute still fails on ProgressDialog.show() as it "fails to find" Android's own progress_dialog.xml!
Anyone know what's happening here?
I suspect it's something to do with the timing, where this is occurring before the main activity has even had a chance to display its screen. These calls are all being made on the main UI thread, but maybe something hasn't completed within the o/s under these conditions.
As a closeout, the problem turned out to be totally unrelated to what I described in my post. Turns out it was due to blindly using some code that had been posted in some online forum showing how to get and use AssetManager. Trouble is, at the end of the block of code he had put "assMan.close()". Well, this closes the asset manager for the entire activity and resources can no longer be accessed!
It took a while to find it since it was not something that I did via my own understanding.

Categories

Resources