Android Debugging, how? - android

Ok so I've finally cobbled enough working parts into my app that its just plain old refusing to do anything now. I understand how to use logcat, but that is about it.
The main problem at the moment is that I get the error
Activity Idle Timeout for HistoryRecord then my package
I need to learn how to do better debugging. Plus if anyone can suggest things I should do for this error please let me know.
I think its something to do with the interactions with the database.
Cheers
EDIT:
What IDE are you using, if any?
Eclipse with Android tool has
moderately good debugging facilities;
set a breakpoint and debug away.
I am using Eclipse
And I know of breakpoints, but not their real use. Where would I set them for this error?
I am used to PHP where errors tell you a specific line to look at is there a way to do this in Eclipse?

In Eclipse if you right click in the margin next to your code - easy place to start is probably in your onCreate method - you can choose to Toggle Breakpoint. This will set a breakpoint at that location.
Now, in Eclipse choose Run->Debug As->Android Application.
This will run your app in the emulator and your app with stop running at your breakpoint. At this point you can step thru your code line by line using F6 I believe.
Once you've hit the breakpoint and your code is paused, use a guide like this http://www.ibm.com/developerworks/library/os-ecbug/ which will highlight all the different things you can do at that point.

Max... If you can wrap the offending line of code in try catch you can log the exception or set a breakpoint at the exception. So for the code below that will throw an exception:
String test= null;
try {
test.length();
}
catch (Exception e) {
Log.d(TAG,"test",e);
}
LogCat will display test,java.lang.NullPointerException blah, blah, blah
OR you can set a breakpoint at the Log.d line and if hit in DEBUG mode the app will pause and the variable window in the DEBUG view will show:
this:MyApp e:NullPointerException
BUT it does not sound like your app is throwing an exception, rather it is timing out on a database call. I would stub out the call to the database and see if the timeout goes away. Then slowly add back code until it times out.
JAL

Related

Android Monitor logcat not displaying any messages - studio version 2.2.1

I am new to app development and have come across an issue my course hasn't yet covered but requires.
I have created a simple app that generates a log entry using Log.i after clicking a button - see screenshot below.
link to screenshot
As you may well see, no logs have been generated at all for the running emulator. This happened on an earlier app and after searching for an answer, found that going to the terminal and finding the appropriate directory, I could restart the adb using the 'kill-server' and 'start-server' commands. As this didn't work, I found the file in windows explorer and double clicked the adb.exe file. This seemed to fix the problem.
Having started another project (the one linked in the screenshot), the same problem has arisen but the same steps do not correct the issue and as such have nothing being generated in the logcat.
*beneath the emulator you see, I have nothing in the search box, the logcat is set to verbose and regex(?) is ticked.
Any help with this would be greatly appreciated as i'm reluctant to proceed with the course material before sorting out this issue.
Thanks.
some additional information I have found in the 'AVD' section of the 'Run' Window :
libpng warnings
adb successful start?
EDIT - requested code
EDIT 2 - It's a bit of a bodge but it seems the adb operator command 'logcat' used in the Terminal, turns the terminal into the logcat i.e. c:..\sdk\adb logcat' - all my missing logs, including the ones generated by the buttonClicked function appear in the terminal and new logs also appear there.
Terminal as logcat
Thank you for your responses but maybe someone knows a way to fix the logcat itself, i'd appreciate the answer. Thanks again.
I have managed to resolve the issue by closing all related software, rebooting my laptop and running the adb.exe file in the ..\android\sdk\platform-tools\ directory before launching the android studio.
Hope this helps if anyone else has the same issue.
Stitches S, I think you are not calling the buttonclicked method anywhere as I haven't seen it calling in the screenshot. But if you are calling it somewhere else then try log.d() to print that. It always works for me.
if you want to see log on button click set the buttonClick method inside the oncreate(), may be its doing nothing that's why not showing any log
this code is working in my case:
public class About_us extends AppCompatActivity {
TextView header, address;
private String Info="Info";
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contact);
header=findViewById(R.id.head);
address= findViewById(R.id.tv_address);
}
public void buttonClick(View view){
Log.d( Info,"button is clickd" );
}
}
and this is my xml view
<TextView android:id="#+id/head"
android:onClick="buttonClick"
android:layout_width="match_parent"
android:background="#color/third"
android:text="#string/app_name"
android:gravity="center"
android:textSize="20sp"
android:textColor="#color/first"
android:layout_height="30dp"/>

The app freezes while debug

I am new in Android and I faced to a problem. I use android studio 2.3, and everything was fine. But after some time, i spotted that an app hangs while i debug. It freeze and works pretty slow. If i turn off debug the app works fine. I tried to clean cach on device and studio but it did not help. I set the my laptop aside and continued work on other pc. In the beginning everything was good but problem returns. I cant figure out the reason and fix it. Has anybody face same problem?
Проблема приложение тормозит во время отладки. Без оной работает нормально. Продолжил работать за другим pc и все было хорошо сперва, но проблема вернулась. Пробовал чистить кешь, удалять но не помогает. Как с этим бороться?
As WieFel wrote, debugger will obviously stop at any breakpoints you created. Make sure that you are not setting your breakpoints on whole methods, as it can cause your debugger to be incredibly slow. Breakpoints should be ideally targeted at single lines of code. You can see all of the breakpoints you've set by Run... -> View Breakpoints or Cmd/Ctrl + Shift + F8.
If you are in debug mode, the app stops at the breakpoints you have set in your code. This gives you the opportunity to look at the variable values at that point in code.
To continue the execution you have to click on the green resume button on the top left of the debug view. -> image:
enter image description here

BubblePopupHelper filling Android Debug Log

So I noticed when I was debugging that there seems to be a tag that's repeating through my app entitled "BubblePopupHelper" with text: "isShowingBubblePopup : false"
Screenshot of the log
To my knowledge, I'm not using or causing it. Does anyone have an idea of what's going on? The application is the one I'm writing.
Upon further inspection, I did notice that every time I'm updating text (via a TextView) it displays onscreen. If there's a better way of doing so, please let me know.
Thanks!
The message seems to be logged by some SDK libraries whenever setText is called in a TextView. I get it in Android Studio developing with min API 14.
One interim solution till Google removes it would be using the filtering feature of Android Studio by writing a RegEx that only includes your log messages. For example if I have all my tags start with 'Braim' then 'Braim.*' can be used
If you want to filter this annoying logs away you can use the following regex:
by Log Tag: (?!^BubblePopupHelper)(^.*$)
Have you added "OnGlobalLayoutListener"?
I've encountered same problem and finally I found that getViewTreeObserver().addOnGlobalLayoutListener caused the problem.
Here is my solution:
textView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
...
textCategory.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});

function is not working properly in Qt

I am making a simple GUI program to change bootanimation of a android phone but from last 4 days I am facing a problem and I don't know whats is reason, here is my code
void MainWindow::bootanim1()
{
QProcess rootboot;
QStringList path6,boottarget;
path6<<ui->lineEdit_6->text();
boottarget<<path6<<" /system/media";
ui->textBrowser->clear();
ui->textBrowser->setText("Remounting partitions...");
rootboot.start("bbin\\adb shell su -c \"busybox mount -o remount,rw /system\"");
rootboot.waitForFinished();
ui->textBrowser->setText("\nInstalling bootanimation.zip");
rootboot.start("bbin\\adb push ",boottarget);
rootboot.waitForFinished();
ui->textBrowser->setText("\nBootanimation has been changed! Try shutting down your phone to see new bootanimation");
}
This function is launched when a button is clicked but my problem is, this is not working! Secondly you can see in the code that to be more informative I have used a textBrowser to show user whats going on like Remounting partitions etc and the lineEdit_6 is the lineEdit widget where user will paste the path of the bootanimation.zip. So my problem is when I click the button only this is shown
Bootanimation has been changed! Try shutting down your phone to see new bootanimation
And everything above it I think is getting skipped, I don't know why? can anyone give me some hint on what I am missing?
Here you are mixing two different methods to give arguments to QProcess:
boottarget<<path6<<" /system/media";
rootboot.start("bbin\\adb push ",boottarget);
First method gives the program name and arguments in one QString.
Second method gives the arguments in a QStringList.
You are trying to give one argument ("push") in the program name string. It doesn't work, when the other arguments are given in a QStringList. The last argument also contains suspicious looking space in the beginning, although I don't know if it causes problems. Try this instead:
QStringList args;
args << "push" << path6 << "/system/media";
rootboot.start("bbin\\adb", args);
And path6 variable probably should be QString instead of QStringList.
Ui requires eventloop to refresh itself. When you do all changes in one function call, then only internal property change, and gui itself doesn't repaint. Use QCoreApplication::processEvents(); right after each ui->textBrowser->setText(...);

LogCat not displaying anything after crash/reinstall

First off, as background: I am on a Mac, running OS X 10.6.7. Using Eclipse for an Android Development class I'm in (and hopefully eventually to actually develop directly for Android).
I had a nasty crash of Eclipse a few days ago, and after restarting I stopped getting any output from LogCat whatsoever. I tried everything I could think of, and I couldn't get anything at all to show up in the log. I tried a nuke-it-from-orbit reinstall of Eclipse, and it's at least made a little bit of a difference. When I run this code snippet I came up with to test things:
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class LogTester extends Activity {
/** Called when the activity is first created. */
public static final String TAG = "LogTester";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d(TAG, "Activity was created");
Log.d(TAG, "Anybody Home?");
}
}
...it shows me this (apparently I can't post images directly as a noob), but when I actually click on the LogTester tab of LogCat, I see nothing. The same thing vice-versa when I click back over to the main log tab, which as you can see should have 11 new items in it.
I tried changing the font since maybe there was some sort of issue with displaying the font, and I've heard there are weird issues with fonts and 10.6.7. But I get a "Problems occurred when invoking code from plug-in: "org.eclipse.ui.workbench"." error and a complete refusal to change the font type. I can't figure out where Eclipse hides this preference so I can try and fiddle with it manually.
Anyone have any ideas/suggestions as to things I should try next? This is absolutely maddening. Thanks!
UPDATE (3/31 1am): I deleted and recreated my AVM for about the 15th time and LogCat suddenly started working. Hell if I know why, but I'm not questioning it.
try switching to DDMS perspective and click on your active emulator in the Device tab. Your Logcat should refresh then.
I know this post is old but a filter got turned on for some reason using Firebase which really confused me for a few mintues while I tried to figure out what was going on.
Here's where you change the filter (in the android monitor panel):

Categories

Resources