Android app crashes without stacktrace on logcat - android

I run my app in Android Studio debugger and get "[AppName] keeps stopping", although it doesn't actually stop. It's just an android.app.Service that appears to be crashing, yet on LogCat I see no stack trace and putting breakpoints in the Service constructor, for example, it doesn't stop there either.

Android Services are running in their own processes. When you configure in your Manifest your service
<service
android:name=".service.SomethingService"
android:enabled="true"
android:exported="false"
android:process=":Something" />
Check logcat for :Something. You should find a process called yourappname:Something. There you find your stacktrace.
For the debugging part of the question you probably need to add this line:
android.os.Debug.waitForDebugger();
where appropriate in your Service' onCreate or so. Then you have time to connect to the process once the server is stuck on that line. Don't forget to remove the line before publishing.

Related

Breakpoint in service not working

I am trying to add a breakpoint to a service running on a separate thread. No matter where I place the breakpoint in the service, they are always ignored.
I am sure that the service is running as I see the Log.e in the logcat. My debug mode is also correctly used as any breakpoint in the main thread of the app works.
Am I missing something? Is debug mode not supported for services in a separate thread?
I just updated Eclipse and Android SDK tools to the latest versions today.
I am testing my application on a device.
The android.os.Debug.waitForDebugger() did the trick. Add this before the line of code you want to debug.
Make sure that you declare the package name in the service tag in the manifest using android:process attribute, for example:
<service android:name=".YourCoolService"
android:process="your.package.here"/>

Application throws an error after relaunch

My application throws an error when I attempt to start it from "Recent applications". Problems :
Error appears only if application was inactive (stopped) for a long time (approximately one hour). I can't catch this error by myself - when I'm killing process by myself and then relaunched it there is no errors!
I can't see Exception log in debugger, since it's disconnects after so long time.
How can I catch such kind of errors in debugger? Looks error appears only when OS kills application by itself.
EDIT
I didn't overrided onResume method. Just onStart, and there is nothing special except instantination of my SQLiteOpenHelper.
even if your app is in paused/stopped state, log cat will still be working as long as device is connected. make sure you selected all logs options in windows > devices > all logs instead of windows > devices > com.your.project .
so when you will try to relaunch crash must be recorded in logCat
if still have any issue, install logcat app from market and refer it for logs.
Sounds like there might be an issue in your
OnResume
call. What is your application doing? Is it using a location manager? Does it have services or threads that need to be restarted? More infomation please.
Look through the Android application lifecycle chart:
http://developer.android.com/reference/android/app/Activity.html
It should help you understand what's going on. If all else fails, add a lot of logging to logcat and see what the output looks like on your end. As long as you don't unplug the device, you shouldn't lose that in Eclipse. If you do, you can always run "adb logcat" from the command line or shell to see exactly what's happening.

Attaching debugger - android problem

I am new to android application development. Whenever I run a new app, after it gets installed and the activity launches, it displays a message saying "application is waiting for the debugger to attach" on the emulator. After that, application runs properly. But I am not getting what that message is and how I can stop it from getting displayed. Could anyone help me...?
its normal... when debugging it takes some time to connect to device or emulator. Its not a error message and u need not worry about it.
Some applications(I assume not yours) needs to have permissions to debug, then u need to have this code
<manifest>
<uses-permission android:name="android.permission.SET_DEBUG_APP"></uses-permission>
</manifest>
In your manifest file .
or else have this
android:debuggable="true"
in the application tag in the AndroidManifest.xml
thanks
It means you run the application in debug mode to solve problems using the button shown on the screenshot.
Try the button at the right beside the debug button instead.

Debugging a service

I have written a service with a remote interface and installed it on my PC's Eclipse AVD. I have a client test harness which starts and invokes methods in the service. Initially I had the service installed by a control class and activity, which I have now removed, so that the manifest for the service looks like:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myname.gridservice"
android:versionCode="1"
android:versionName="1.0">
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:debuggable="true">
<service
android:enabled="true"
android:debuggable="true"
android:name="OverlayService">
<intent-filter>
<action android:name="com.myname.OverlayService.SERVICE"/>
<action android:name="com.myname.gridservice.IRemoteInterface" />
</intent-filter>
</service>
</application>
</manifest>
so there's no activity tag.
When I launch it from the debug icon in Eclipse, the console tells me that it's installing the apk (which it is), but it does not appear as a debug thread and breakpoints aren't triggered, although the service's behaviour is OK as far as the client sees it. If I wrap the service tag in an activity tag which has an associated class and launch that, then I can debug it.
Is it possible to debug the service without wrapping it in an activity?
Here's what you can do in four steps:
First: In the first interesting method of your service (I used on create):
/* (non-Javadoc)
* #see android.app.Service#onCreate()
*/
#Override
public void onCreate() {
super.onCreate();
//whatever else you have to to here...
android.os.Debug.waitForDebugger(); // this line is key
}
Second: Set break points anywhere after the waitForDebugger command.
Third: Launch app via debug button in your IDE (Eclipse/Android Studio/...). (You should probably have removed the main launch activity from the manifest by now)
Last: Launch adb and run the command to start a service:
cd $PLATFORM_TOOLS
adb shell
am startservice -n com.google.android.apps.gtalkservice/com.google.android.gtalkservice.service.GTalkService
just make sure you don't forget this line of code in your code and release your apk. if you try running your app without the debugger the line below will get stuck.
android.os.Debug.waitForDebugger();
also you can use the following to determine if the debugger is connected:
android.os.Debug.isDebuggerConnected(); //Determine if a debugger is currently attached.
Edit 2018 button icon changed
This is pretty simple, you can connect to your application service. Assuming that running the debugger doesn't work, you can press the choose process option by pressing the debug with an arrow icon pictured above. Select your service and you should now be able to debug your service.
I think it should be done programmatically with android.os.Debug.waitForDebugger();
This works in Android Studio. There might be a similar way in Eclipse I suppose.
run your project in debug mode
attach debugger to your service process
Some of the answers correctly mention that you'd want to insert
android.os.Debug.waitForDebugger();
into the first interesting method of the service. However, it's not clear from those answers, that the Android Studio debugger will not start automatically when the service is started.
Instead, you also need to wait till the 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 service's separate process. You can then select it to complete the process of attaching the debugger to the service.
Edit, Aug 2020: the button icon is the same in Android Studio 4.0

What is going on with the "Unexpected resume of <packagename> while already resumed" message on Android?

Several of my Android applications show the following type message in the logcat output:
I/UsageStats( 59): Unexpected resume of com.totsp.test while already resumed in com.totsp.test
In this case I created the default Hello World app by letting the ADT tool generate it, and it still gets this message. I am not doing anything special in onCreate and don't even have any other methods defined.
I realize this is an INFO level message, and it doesn't appear to hurt anything, but I was curious what was going on so I made a test application that keeps track of the onResume invocations. It is indeed re-resuming when this occurs. I'm wondering why this this occurs? While I haven't noticed a problem (other than these annoying log messages), it seems like it could be using more resources than necessary to do all this stuff an extra time.
I have searched and read a similar question here on SO, and the answer there seems dubious to me: Unexpected resume of "package name" while already resumed in ''package name" Error in Android. Specifically, no, you don't want to use android:configChanges="orientation" because that is just subverting the orientation tear down/resume, rather than fixing it. Even the documentation notes "this attribute should be avoided and used only as a last-resort" (http://developer.android.com/intl/de/guide/topics/manifest/activity-element.html#config).
Also I have seen thread in the Android dev group where Mr. Murphy says the "unexpected resume" is "benign": http://groups.google.com/group/android-developers/browse_thread/thread/567410dbfcc163c2.
I'll dig into the source when I get a chance, but I figured I would first just ask the all-knowing hivemind and see if someone already knows: why does this occur, and is it truly benign?
Don't worry about it, it is just a message from some internal state tracking that is not really a problem (hence it being INFO level). I'll make sure it is removed in the next platform version.
My whole Activity flow changes every time this error comes,
but i have handled this by adding android:configChanges="orientation" in the activity in Manifest File.
<activity android:name=".YourActivity" android:label="#string/app_name" android:configChanges="orientation" android:screenOrientation="nosensor">
Hope this helps you

Categories

Resources