How do you debug an Android app that crashes the device? - android

I'm currently having an issue with certain Samsung devices where starting an activity with an intro animation sometimes causes the whole device to crash.
The app essentially transitions from an Activity with a VideoView to another activity with a VideoView. The video of the activity that just started stutters in a loop for about 10 seconds before the whole device crashes and restarts.
It's not crashing the device all the time, but is limited to a couple Samsung devices from what I've tested.
I've looked at crash logs of the device which currently seem to be inconclusive from what I can see.
Important but relevant note, I am finishing the activity once starting the next.

You could try to attach the debugger manually through Android Studio if your process is alive long enough after the boot sequence.
Source:
https://developer.android.com/studio/debug/index.html
One more thing you could try is to put the 'wait for debugger' instruction in your code, using the Debug.waitForDebugger() method.
Source: https://developer.android.com/reference/android/os/Debug.html#waitForDebugger()
Other than that, you could put a lot of logs in your code, then fetch them using adb logcat > crash-log.txt command from your CMD/Terminal.

Related

Android device doesn't launch activities on the screen while espresso testing

As long as I saw in a YouTube video that an android device tends to launch and show activities that are launched in my test, I think there is a problem here, since mine doesn't react at all (the screen is always on though, animations are turned off).
When I was trying to test the activity which runs first in the app (logically), I tried to open the app by myself while testing and somehow it worked. Now I'm testing another one and this trick doesn't work anymore.
Anyways I always get the error:
java.lang.AssertionError: Activity never becomes requested state "[RESUMED, STARTED, CREATED, DESTROYED]"
My test code uncludes:
val scenario = ActivityScenario.launch(HomeActivity::class.java)
And then I just check the presence of a layout element (textview or anything)
Any ideas why it may occur?
Thanks in advance
UPD: android emulator works fine.
this also happening to my test when following codelab from google kotlin unit test
when im trying to run the test via emulator, it run perfectly, but when i run into my device, which is xiaomi redmi note 5, the error showed up like yours,
i found an answer in this question and it directed to this github
i try to enable app permission "Display pop-up windows while running in the background", and when i run the test again, it passes

Android studio: Error: Activity not started, unknown error code 5

Currently developing an Android app for my company.
Everything was fine, till my last debugging session on my test-device (tablet attached to android via adb).
When I try to run or debug my app, the "Run App" log simply shows:
Error: Activity not started, unknown error code 5
There is no further information, no stack trace, no nothing...
I tried to figure out, what I changed since the last time, but nothing seems to fix this.
Has anybody else had this error code 5 before and can help me?
Long story short: Unknown error 5 means (at least in my case), there is a lock (meaning a pinned app) on the device, so no other app can be started.
After a bunch of things I tried, I finally figured this out.
My app uses startLockTask() to pin it (so you can't accidentally press one of the navigation buttons).
The problem was, that this lock seemed to be active, even though the app wasn't running. I only realized that, after I tried to push the home button on my tablet (it already showed the android home screen, so it didn't occur to me, to try that...).
Once I released the lock (pressing both Back and Overview at the same time), I could start the debugging again, with no problem.
Restarting the device fixed the problem

Is there somethign similar to the Windows Task Manager for the android emulator

I was studying some tutorials on Android programming and I realized that pressing the Home button on the emulator takes me tot he phones Desktop, but my sample that was running at the time only goes to the background and does not get destroyed. However, if I press the return button, the app is destroyed as well. So I am assuming there might be other apps running int he background as well, those which I am not aware of. Is there something in the android emulator resembling the task manager from windows, which shows what apps are currently running on the phone? I don't have a smartphone with me, but I remember seeing something like that on my friend's smartphone a few days ago. It wasn't an external app but was something built into the phone, I could access it by going to Settings or something.
Is there a task manager built into the android emulator, or is there any other way I can see such things through the SDK debugger?
Inside the settings, there is a list of currently running processes.
First , Leaving the activity does not mean the process ends, It is just not invisible . When the Os needs more memory ,it will be recovered.
If you want to have a backup process, you can start a back service.
http://developer.android.com/reference/android/app/Service.html
Here is how I end a process (only works on Android 4.0+).
Instead of pressing home, press recent and swipe away the process you want to end. Then press home (or back).
You can also use this to close those nasty apps that prevent you from closing them by not allowing back button to work on their main screens.
This is much quicker than having to go to settings, etc.

Android tablet camera not working

I am developing an application for Android ICS's 7 inch tablet. In application there is use of camera function to capture image. I allocate camera when somebody opens activity and after work completes camera releases. This is working fine. When I test this thing for 50 times continually with 4~5 frequency of opening and closing activity, application do not respond to application, Neither for in built applications and suddenly screen gets black and I need to restart system again to continue previous work. Why this problem is coming in system? Is any solution. Thanking you for reply.
It could be to do with the Nexus 7's lack of a back facing camera. This can cause problems as specified here
I can't think of anything else right now. Try adding a stack trace to your answer so we can see what went wrong.

Signed android app behaves different from when run manually on device from Eclipse?

I'm feeling screwed up now after working on this problem for the last century. Thanks in advance for your help!
What Happened: I develop an app, which is a game that contains a game
activity that uses CountDownTimers for timed game rounds. Pausing,
exiting the app from this activity (via pressing the power button,
home button etc.) works fine when tested on my Samsung Galaxy Tab 7",
running the unsigned app from Eclipse before it has been signed.
Ecstatic that I've completed my work, I go ahead and sign the freaking apk in
CMD. I test the signed app just to check that it works fine by
copy+pasting the signed .apk into the SD card of the same Galaxy Tab
and then installing it after removing all the old data of the app run from
Eclipse but OF COURSE IT DOESN'T WORK.
Things going wrong include the activity not pausing when I press the
power button when the timed round is being run (after I power the device back on I discover that the timer has been running while the screen was powered off and is still running, and my pause game dialog is nowhere to be found), the activity being
closed when I press the home key (after I press the home key and open
the app again the app restarts from the introductory splash screen of
the app) and lastly, when I pause the game midway, power off and on
the screen, hit resume on the pause game dialog - the game timer goes from something like
18.42s straight to 0.00s and continues from there into the next activity.
Okay, so that is very much more of a story than a question about code - but here's the technical question - why is my signed app behaving differently from the unsigned one that was run from Eclipse? I'm not providing any code here of how i did those things, since that should be irrelevant considering that they work in the first place (as in by running the app on my device while developing in Eclipse).
So very nearly there... URGH
Not sure if this is actually your problem ... but the most common reason that a signed app does not work when the unsigned/Eclipse version does is that building the signed app generally includes a Proguard obfuscation/optimization step.
One of the consequences of Proguard optimization is that some of the classes/methods referenced in either your XML layouts or using reflection may no longer have the same name (or may have been optimized out altogether).
The easiest/fastest way to check is to look at the logcat trace - there'll be a ClassNotFoundException or MethodNotFoundException or somesuch.

Categories

Resources