How do I crash my phonegap app deliberately? - android

I would like to add a feature of restarting from crash for my applications. So, I need to simulate the crash abort. It should be easy but I just can't make it crash itself.
It's a phonegap application, and the best would be crashed from the javascript in html. But no matter I tried, the application does not crash, the application is just hang there and not responding any clicks. I've tried to write some codes in the java phonegap plugins, however, I can't make it crash as well. Any suggestion?

Try something like this:
Object obj=null;
obj.toString();
This should cause a NullPointerException. When you don't catch it anywhere you should be able to test your recovery functionality. But think about a possibility to get bugreports from your users - elsewhere you will never be able to fix ugly bugs that happen only on other peoples devices.

Related

Why My Phone hangs up after app is crashing which I am working on?

Working on a app which contains a lot of data in the home page like lot of gif images ,maps ,videos and many other things.
The real problem is my app now hangs up almost in every device after app is crashed and then I need to restart device. It's a weird behavior as I don't get any error or exception in the logcat.
How could I resolve the root cause. I have even tried to put less load on main thread but still problem is there.
I have used Services in the app to fetch the data from the server in the background without interrupting user. Is this may the cause ?
Not a lot of help can be offered based on your question.
Possible debugging technique:
Use Try catch block, and check for exceptions.
Use built in debugger in Android Studio, for step by step traversal.
If you are getting information from web, try doing it in background threads.

Debug Android app crash on startup without logcat or ACRA

I'm having a problem where an app I'm developing is working on mobile devices (tested on 4 different devices), but crashing when I try to test it on my tablet. The tablet I'm using is a Tesco Hudl 2, which, although being a good quality low cost device, lacks adb drivers and so you can't debug apps through USB and get the Logcat data. The app was developed using Android Studio.
With other apps I have developed, I have just set up ACRA in the project so I can still get debug information from a crash. This time however, the app is crashing without any information from ACRA and so I'm not quite sure what is going wrong. I'm pretty sure I've set up ACRA correctly given that I've used it in several projects before and see nothing wrong this time. Can it be that whatever is going wrong is happening too early for ACRA to catch?
I have pulled out all the code from the activity so the only thing that happens in code is that ACRA gets initialized in the derived Application class (note that the crash exists without ACRA). The app also uses Google maps and a provider for search suggestions. If there is any code anyone wants to see just ask, but I'm unsure what exactly to post up since everything else was stripped out. So, does anyone have any idea on what I can do to solve this, or what tools I can use to catch whatever sort of errors happen so early in the apps lifecycle?
Thanks
Update with strange behaviour... Downloaded Crashlytics and it also did not catch the crash. I copied the project and removed every .java file except the Application, Activity and provider. The provider functions were empty (save for the return value of 0/false/null/whatever), the application class just initialized Crashlyitcs and the Activity class was empty. This then worked, I was even able to add in a lot of the code and get the google map to load.
Now if I do the same in my main project, except don't delete the .java files, the crash still happens. The classes in these files are not used so I have no idea how they can be causing the crash. Otherwise all the xml, gradle, resources are identical (except the package and app name). Very confusing...
Consider using one of the apps to view logcat on the device:
https://play.google.com/store/apps/details?id=com.nolanlawson.logcat
https://play.google.com/store/apps/details?id=org.jtb.alogcat
Also try using Crashlytics. Maybe it will catch your crash?
But yeah, it's possible to have a crash before any crash reporter (ACRA or Crashlytics) will have a chance to catch it.
And one more note, maybe there is a way to enabled ADB over WiFi.
Normally you would need to enable it via adb but maybe in case of this cheap and strange tablet, there is an option for that enabled in the ROM?
Ok! So it's 1am and I decided to have one final attempt to fix, which I think I did. In my manifest, I had things like
<activity
android:name=".MyActivity"
...
for example, and while this worked fine on the mobiles, for some reason the Hudl required the complete package name, i.e. com.mypackage.MyActivity. Not sure why this is the case but it appears to have fixed the problem.

How to detect that my app has crahed because it ran out of memory?

Is there a way to find out (write to log) that my app hasn't just crashed, but has run out of memory? Can I install some kind of a global exception handler?
I have my own custom Application class, if that helps.
Note: the app has a native (C++) core, and I need to be able to detect that the core has run out of memory, as well as the Java wrapper. I don't need to know where it happened, though (don't think it's possible?..), just the fact.
You can have your crash log system like Acra, Crashlytics, Parse and so on. If you have time you should write your own, but that is not as simple as you may think. Too us a while to make a rock solid solution :/

Get crash information when debugger is not attached?

I'm developing an app using Android Studio. Now I'm facing a bug where the app crashes when I do the following:
Press the home button.
Use the device for some 10 minutes (i.e. wait).
Run the app again. Crash!
There is no easier way to reproduce the crash (nothing in onResume). As you can imagine, this is kind of hard to debug. In an ideal world, the OS (Android 5.0) would let me send a bug report to myself. The app is not published yet, so I don't see how I could get hold of the crash dump. Is it saved somewhere on the device?
I did try to debug the app from Developer Options, using the wait for debugger setting and then attaching to the process from within Android Studio. This, however, seems to make the bug go away. (The app is probably restarted.)
Q: How do I find the cause of the crash given these circumstances?
My intuition tells me that you are using some 'static' variables/fields in your application.
When your app goes to background and it is not used, system could drop process (because of memory management) of this application from memory. When you come back, Application object and all application proces in system is recreated, so all static variables are cleared/reinitialized.
Am i right?
Try looking into your logcat and if that is not an option for you. try some crash analytic like the following.
https://mint.splunk.com/
Integrate it in your app just with a single line and whenever your app get crashed you will receive a mail of your crash logs..
it will easily help you to determine your crash scenario..
And just out of curiosity are you using any singlton class in your Activity.?
I found the crash using adb as described here. Never realized that logcat keeps logs from previous executions. Nice!

UncaughtExceptionHandler for Errors in Android

I am working on an app with remote exception-handling. That is, if an exception happens somewhere that wasn't expected, the app closes gracefully and a report is generated in the log on our server. I am using the UncaughtExceptionHandler interface for this and it works well except that it does not seem to catch Throwables that are actually Errors.
Obviously, the best solution is to just handle everything and/or not allow anything to throw an Error in the first place. For the sake of thorough error-handling, however, I would like to be able to catch unexpected Errors as well as Exceptions. I was unable to find anything like an UncaughtErrorHandler in Android, does anyone know if such a thing is possible?
There is generally no way to catch Errors: typically once an Error happens you can't actually intercept it. As far as I know there is no fully-supported mechanism in the Java language to catch these, and there really isn't any one on Android either.
You might want to check out several SDKs like Crittercism. A rudimentary way to achieve what you want is to use Thread.setDefaultUncaughtExceptionHandler().

Categories

Resources