Network availability to make a call - android

In my application I have written code to make a call to helpline just by clicking on button. When I copy this application to my Android device, if the network is not available it exits the application. I want to display a error message rather than exiting.
One more issue,I have written code to add a helpline number to contactbook when the application is loaded into device. When i check it on emulator it works, but on device it's not working :(

Use logcat to see why your application is exiting.
For example if its due to an error or uncaught exception, detect it (make sure an object isn't null before calling its methods) or catch and handle the exception.

Related

Android application unknown host exception

I developed an application for android tablets. In that application, when I get into the app and after doing some actions I keep the application idle for half an hour or sometimes and again get back into the app to perform any action, it leads to application crash with UNKNOWNHOSTEXCEPTION.I don't know why it happens even after i gave INTERNET permission in Android manifest file.I have been searching solution for this problem for one week...still i could not able to find any solution.i used fragments in my application...please help me...
Likely the tablet temporary switching off the network to save energy. Add try/catch to your requests and probably do 2-3 tries in some interval before you will show error to user.
This type of exception happens when you try to switch networks , or the required Network isn't available.
Use try/catch block to prevent crashing of application.

How to show message like "the application has crashed, but a report is sent to the admin" in android

I am new to android and my application involves lot of internet access and many times when the data that needs to come from a web service is unavailable my application crashes.
I tried to avoid as many cases as possible, but i am not sure if my application is crash free.
I am using an application named "delight circle" and sometimes that application crashes and shows me this Toast:
"The application has crashed and a report is sent to the admin"
and takes me back to the previous activity or previous action, and from here i can use the application normally again.
I have 2 questions:
How to make the application work normally after it crashes once. In my application, if it crashes then it asks me for force close and when i click it, it takes me to the previous activity(or action) but nothing works there, if i try to do anything it asks for force close again, i eventually end up force closing the application from Settings --> Applications --> myApp --> foce close.
How to send a report about what actually caused the application to crash?? Right now i have a lot of logs in every activity so, now if it crashes i can find out the exact reason and solve. But when i release the application how can i do this?
Thank You
You have to use UnCaughtExceptionHandler for this.
Here is a example,
http://trivedihardik.wordpress.com/2011/08/20/how-to-avoid-force-close-error-in-android/
Once you override the Exception Handler, you will be provided with access to the Log and from where, either you can send the error log which you get the from the SatckTrace as an Email or use Apis to do it.
I can give an answer to your second question, that is "How to send a report about what actually caused the application to crash" Try Crittercism in your code. It will help you to find the exact cause of failing the application. Not only that, it has so many features, like Live Stats, Unresolved crashes, Crash alarms and more.

Getting debug logs - iPhone

On Android I am using the android.util.Log to log within my application and during development I am using the adb logcat or Eclipse to see the logs - I use it even more then debugging...
On device I can save the logfile from my code or use some application form Android Market to save the logs - e.g. aLogCat.
Now can I do the same on the iPhone? I can use the NSLog(#"message");, but can I easily save the log file from my application and access it? Are there any ways for that?
Regards,
STeN
This is from NSFoundation reference
NSLog:
Simply calls NSLogv, passing it a variable number of arguments.
NSLogv:
Logs an error message to the Apple System Log facility (see man 3 asl). If the STDERR_FILENO file descriptor has been redirected away from the default or is going to a tty, it will also be written there. If you want to direct output elsewhere, you need to use a custom logging facility.
Thus, it is only a matter of redirecting the file-descriptor "stderr" (2) to a custom file, and you will get everything that you print using NSLog in that file.
This seems to be exactly what you want.
Note that if you want to get logs on console when you are connected to the debugger, you can wrap your code around this to avoid redirection in this case:
if (!isatty(STDERR_FILENO)) { // Not connected to any terminal
// your redirection code
}
You can access the console log from Organizer->Device->Your device->console.
If that is not powerful enough, consider using utilities like NSLogger.
The previous answers are good; also see this if you're inclined to making system calls.

Android: How should I respond to "Hot Code Replace Failed" dialog in Eclipse?

When my Android application is already running and I change the code I get the "Hot Code Replace Failed" dialog.
I'm wondering what the correct response is (terminate or disconnect) if I want Eclipse to update my code on the device when I encounter it.
What is the difference between terminate and disconnect?
Also, I'm wondering if I click the "Do not show error when hot code replace is not supported", what will Eclipse do in the future when this scenario occurs?
Depending on the VM used (Dalvik in this case), some code changes can be made whilst debugging that will 'hot deploy' or 'hot replace'. This means that the code changes will immediately take effect on the emulator and you can test them without the need to re-deploy your app. This sort of hot re-deployment is more commonly used when working with enterprise applications that may take 10 minutes to build and deploy and so wastes a lot of time during development.
The HotSpot VM (the VM usually used on PCs) allows only simple code replacement and fails if you try to add/rename a field member or method. I'm not sure what sort of support the Dalvik VM provides but if you make a change it does not support you'll get that dialog box.
Now, as for the buttons:
Continue: Accept that the changes you have made will not take effect immediately in the emulator and continue debugging
Terminate: Kill the app
Disconnect: Do not kill the app but end the debugging session (i.e. disconnect the debugger)
If you check the box, it will always Continue.
I'm wondering what the correct response is (terminate or disconnect) if I want Eclipse to update my code on the device when I encounter it.
There's no direct way to have Eclipse update your running code on the emulator when you encounter this dialog as the Dalvik VM does not suppot hot swap, i.e. the update of running code. You'll have to redeploy the app to your emulator manually.
What is the difference between terminate and disconnect?
Terminate will terminate the app being debugged on the emulator/device.
Disconnect will just disconnect the debugger, and leave the app running on the emulator/device.
Also, I'm wondering if I click the "Do not show error when hot code replace is not supported", what will Eclipse do in the future when this scenario occurs?
It "won't show error when hot code replace is not supported" obviously ;) -- i.e. it won't warn you and any changes you do will not be hot-swapped into the running app (because the Dalvik VM doesn't support hot-swapping like Oracle's JVM for example).
I usually Terminate and then re-publish my application with the changed code.

Logging inside Framework?

I am trying to develop small application for reset Logging on Phone.
Can some one throw some Lights on how to achieve logging in AndriodRunTimeInit whenever there is exception? I want to write into file whenever there is RunTime exception.
It is recommended that you use Android's built in logging via Log. You can access the log via adb logcat and don't have to worry about anything else.

Categories

Resources