Android Dev Tips I Catch run-time exceptions, send crash reports and still remain user friendly Stefan Anca 02.07.2012.

Slides:



Advertisements
Similar presentations
The Ultimate Troubleshooter TUT July 26, 2005 Lorain County Computer Computer Users Group Users Group.
Advertisements

Google Android Introduction to Mobile Computing. Android is part of the build a better phone process Open Handset Alliance produces Android Comprises.
1. What is Essex Scheduler? 2. Why Android? 3. Software design 4. Application graphics 5. Releasing to Google Play 6. Application maintenance Essex Scheduler.
Cosc 5/4730 Android Services. What is a service? From android developer web pages: Most confusion about the Service class actually revolves around what.
Pete Houston Maintenance, Improvement, Patch, Optimization, Errors, Bugs, …. oh I’m totally FUCKED UP! Coders tend to make many.
Exception Handling Introduction Exception handling is a mechanism to handle exceptions. Exceptions are error like situations. It is difficult to decide.
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
The Activity Class 1.  One application component type  Provides a visual interface for a single screen  Typically supports one thing a user can do,
NEW PRODUCT INTRODUCTION: SalesLink TOUCH April 2015.
Room Locator App Aabhas Sharma Vinayak Gokhale Yehia Khoja 1 Room Locator App.
Best games in the world are free!. Agenda 1. About Game Insight 2. Why Android 3. Market Opportunity 4. Emerging Markets 5. Secrets to success.
Top 5 Small Business Tips on Creating a Mobile App.
Min Kwan Park Test Tech Lead Visual C# QA team. Fail fast To-Dos for fail fast Analyze issues Information for further action Q&A Agenda.
Developing Push Notifications (C2DM) for Android Vijai Co-Founder Adhish Technologies, Sweet’N’Spicy apps.
UI Design Patterns & Best Practices Mike Wolfson July 22, 2010.
Object Oriented Programming
And other languages…. must remember to check return value OR, must pass label/exception handler to every function Caller Function return status Caller.
COMPUTER PROGRAMMING 2 Exceptions. What are Exceptions? Unexpected events that happen when the code is executing (during runtime). Exceptions are types.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Concurrency in Android with.
Mobile Programming Lecture 16 The Facebook API. Agenda The Setup Hello, Facebook User Facebook Permissions Access Token Logging Out Graph API.
Welcome message. The background image would be an image of Electronic Circuit And have a flash action script to animate 0 and 1. This site would be for.
Google Cloud Messaging for Android (GCM) is a free service that helps developers send data from servers to their Android.
Networking: Part 2 (Accessing the Internet). The UI Thread When an application is launched, the system creates a “main” UI thread responsible for handling.
Part 04 – Preparing to Deploy to the Cloud Entity Framework and MVC Series Tom Perkins NTPCUG.
Asst Prof. Saeed Ahmadi Software Engineering CSF Kabul University 1.
Individual mobile platform for cafe & restaurant automation three it’s as easy one two as.
Threads and Services. Background Processes One of the key differences between Android and iPhone is the ability to run things in the background on Android.
1 Software Construction and Evolution - CSSE 375 Exception Handling - Principles Steve Chenoweth, RHIT Above – Exception handling on the ENIAC. From
Object Oriented Software Development 8. Exceptions, testing and debugging.
Google Apps (Education Edition) A step guide to a successful deployment January 10 th, 2008 California Technology Assistance Project
It’s all about your mission. Francis Scudellari Trish Perkins Cloud Consultants Validation.
Cosc 5/4730 Android Communications Intents, callbacks, and setters.
BIO Java 1 Exception Handling Aborting program not always a good idea – can’t lose messages – E-commerce: must ensure correct handling of private.
Maps Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.
Android System Security Xinming Ou. Android System Basics An open-source operating system for mobile devices (AOSP, led by Google) – Consists of a base.
FCM Workflow using GCM.
our digital journey, one year on a bit of background… Crackerjackpot needed a new website! What we had just wasn’t doing the job Challenge to get the.
Exception-Handling Fundamentals  A Java exception is an object that describes an exceptional (that is, error) condition that has occurred in a piece of.
Open Source Web Development Brad Shields CEN/CET.
Services Background operating component without a visual interface Running in the background indefinitely Differently from Activity, Service in Android.
Tips And Tricks For Getting The Most Out Of The CPUG Discussion Board.
Power Guru: Implementing Smart Power Management on the Android Platform Written by Raef Mchaymech.
(c) University of Washington10-1 CSC 143 Java Errors and Exceptions Reading: Ch. 15.
Lecture 2: Android Concepts
Android Alert Dialog. Alert Dialog Place Button to open the dialog. public class MainActivity extends ActionBarActivity { private static Button button_sbm;
Cosc 4735 LocationAware API. Previous on … Before we looked at GPS location. – d-gpslocation.pptx
Dextrosoft SCHEDULED PHONE BACKUP Backup your mobile life Version Copyright © 2015 Dextrosoft Private Limited. All Rights Reserved.
CU Student Organizer Trey McAlhany CPSC 482 Mobile Software Development Clemson University April 14, 2015.
COP 3330 Notes 3/7. Today’s Topics Exceptions Abstract Classes.
Lecture 5: Location Topics: Google Play Services, Location API Date: Feb 16, 2016.
CS 61B Data Structures and Programming Methodology July 7, 2008 David Sun.
JLink Linking Mathematica with Java and the other way round…
Web Analytics Fundamentals Presented by Tejaswi, Chandrika, Sunil.
Fuzzing Machine By Nikolaj Tolkačiov.
Intro To Android Programming
Concurrency in Android
Android 01: Fundamentals
Tracking System (Android)
Security service management of tomorrow
Ways to protect yourself against hackers
Java Programming Language
CS499 – Mobile Application Development
Android Speech Recognition
How to Troubleshoot Sync Errors with the Gmail Android App?
Mobile Computing With Android ACST 4550 Alerts
Exception Handling in Java
Android Topics UI Thread and Limited processing resources
Activities and Intents
Android Topics What are Intents? Implicit Intents vs. Explicit Intents
Notifying from the Background
Presentation transcript:

Android Dev Tips I Catch run-time exceptions, send crash reports and still remain user friendly Stefan Anca

Agenda Problem Analysis Solutions Error Reporting Implementation Conclusions Agenda

Problem: Runtime Crash Problem Analysis

Reasons Inflexible programming: internet unreachable, camera not available, sensor missing, etc. SDK level incompatible (project target, android:minSdkVersion) Configuration Change unhandled Android problems Hardware problems … Problem Analysis

Solutions 1.Program better! 2.Test it yourself! Solutions

Solutions (II) 3.Pay others to test it for you before launch – AppDemoStore – TESTDROID Cloud – Vodafone online test & verification (Perfecto Mobile) 4.Built-in Error Reporting – Google Error Reporting – Do-it-yourself Error Reporting Solutions

Google Error Reporting Application Error Reporting in Google Play Available since SDK 8 (Froyo) Reports available in the market account Somewhat Unreliable Users don’t report! Error Reporting

DIY Error Reporting ACRA (free lib) Android Error Reporter (free lib) android-remote-stacktrace (free lib) android-log-collector (free apk) Apphance (online service - freemium) BugSense (online service - freemium) Hockey App (online service - $10/month) Crittercism (online service - freemium) … Error Reporting

DIY Error Reporting (II) How is it done? 1.Catch Exception 2.Show user a nice dialog 3.Ask the user to send error report (HTTP/ ) 4.Analyze report (server side) Error Reporting

1. Catch Exception UncaughtExceptionHandler import java.lang.Thread.UncaughtExceptionHandler; public class CustomExceptionHandler implements public void uncaughtException(Thread t, Throwable e) { } } public class FlipCardApplication extends Application public void onCreate() { super.onCreate(); Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(this)); }} Implementation

2-3. Show user a nice dialog; Ask user to send error report Implementation

2-3. Show user a nice dialog; Ask user to send error report(II) AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setMessage("An unexpected crash occured. Would you like to send " + "the developer a crash report and contribute to the prevention of " + "such problems in the future?"); alert.setTitle(appName); alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Send report, then die } }); alert.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Die } }); alert.show(); Implementation

Technical Details The activity where the crash takes place must die! The application must die! Otherwise, unstable state. defaultUEH = Thread.getDefaultUncaughtExceptionHandler(); defaultUEH.uncaughtException(t, e); //Raises Standard Error Dialog OR Process.killProcess(Process.myPid()); //Dirty but no dialog System.exit(10); //Make sure to clean activity/app state before this Error reporting must take place in a different activity! Error reporting must take place in a different process! <activity android:name="com.package.CrashReportActivity" android:taskAffinity="com.package.TASK.CrashReportActivity" android:process="com.package.CrashReportProcess" /> Implementation

Uncaught Exception Handler public void uncaughtException(Thread t, Throwable e) { String report = Log.getStackTraceString(e) + '\n'; // If the exception was thrown in a background thread inside // AsyncTask, then the actual exception can be found with getCause Throwable cause = e.getCause(); if (cause != null) report += Log.getStackTraceString(cause); Intent intent = new Intent(ctx, CrashReportActivity.class); intent.putExtra('report', report); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ctx.startActivity(intent); currentActivity.finish(); //IMPORTANT: Clean up app state! Process.killProcess(Process.myPid()); //Dirty System.exit(10); } Implementation

Crash Report Activity public class CrashReportActivity extends Activity protected void onCreate(Bundle savedInstance) { super.onCreate(savedInstance); Bundle extras = getIntent().getExtras(); if (extras != null) { this.report = extras.getString('report'); } Implementation

Crash Report Activity protected void onStart() { super.onStart(); AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setMessage("An unexpected crash occurred..."); alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Intent i = new Intent(Intent.ACTION_SEND); i.putExtra(Intent.EXTRA_ , i.putExtra(Intent.EXTRA_SUBJECT, 'Crash Report'); i.putExtra(Intent.EXTRA_TEXT, this.report); i.setType("message/rfc822"); CrashReportActivity.startActivity(Intent.createChooser(i, "Send crash report")); Process.killProcess(Process.myPid()); System.exit(10); } }); alert.setNegativeButton("No",...); alert.show(); } Implementation

4. Analyze reports Send Crash Reports to Server – HTTP POST – Server – PHP Script + MySQL Database – Google Spreadsheet (ACRA) – Inbox Implementation

Extra Error Reporting Users don’t report when asked to! Short reporting through Google Analytics tracker.trackPageView("ABCs/85/google/Error/" + errorLine); Implementation – Uncaught Exception Handler: Pattern pattern = Pattern.compile("^\\s*at (com.fivepumpkins.*)", Pattern.MULTILINE); Matcher matcher; matcher = pattern.matcher(report); // report is the stack trace string if (matcher.find()) { String errorLine = matcher.group(1); tracker.trackPageView("ABCs/" + appVersion + "/" + publisher + "/Error" + errorLine); } Implementation

Google Analytics Reports Implementation

4. Analyze reports (II) Application: ABCs (by Fivepumpkins) Interval: – (~6 weeks) Visits: 83,471 Unique Visitors: 24, Errors 8 Crash Reports!!! 5 s reporting bugs Conclusions

Users hate bugs but hate reporting them even more! User-driven Error-Reporting is the tip of the iceberg Automatic Crash Reports are the safest bet Users are the best QA Reply to active users! Conclusions

References References

Thank you Questions? End