i can't send email in UncaughtExceptionHandler for Service

by codefish » Thu, 22 Jul 2010 11:48:02 GMT


Sponsored Links
 i want to handle exceptions in Service.
my exception handler sends error report email.
so i add FLAG_ACTIVITY_NEW_TASK flag and it works fine in onCreate().
but in UncaughtExceptionHandler, it doesn't send email.

so how it can send email in uncaughtException()?

public class ErrorReporter implements Thread.UncaughtExceptionHandler
{
  //....
  public void uncaughtException(Thread t, Throwable e) {
    // ...
    SendErrorMail(this.CurContext, Report);
  }

  private void SendErrorMail(Context _context, String ErrorContent) {
        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        String subject = ("Crash Report - Android ErrorReporter");
        String body = ErrorContent + "\n\n";
        sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[]
{"92soc...@gmail.com"});
        sendIntent.putExtra(Intent.EXTRA_TEXT, body);
        sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
        sendIntent.setType("message/rfc822");
        Intent i = Intent.createChooser(sendIntent, "Title:");
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  // because
Service ...
        _context.startActivity(i);
  }
}

thank you

--



i can't send email in UncaughtExceptionHandler for Service

by DanH » Thu, 22 Jul 2010 20:40:59 GMT


 First off, are you sure that your UncaughtExceptionHandler is not
throwing an exception?




--


Sponsored Links


i can't send email in UncaughtExceptionHandler for Service

by Joseph Earl » Fri, 23 Jul 2010 03:30:39 GMT


 You email is not getting sent because you are not doing anything with
your sendIntent. You create it but then never use it.



--



i can't send email in UncaughtExceptionHandler for Service

by Joseph Earl » Fri, 23 Jul 2010 03:34:33 GMT


 Scratch that. My mistake. I missed the Intent.createChooser line.
Have you taken a look at: 
 http://www.anddev.org/email_send_intent_intentchooser-t3295.html 
?

I don't see any immediate errors in your code.





--



i can't send email in UncaughtExceptionHandler for Service

by codefish » Thu, 29 Jul 2010 19:45:45 GMT


 thank you for your reply
I added try/catch code but I got no exception
and it still doesn't send a email ;(

        try
        {
            _context.startActivity(i);
            Log.d(LOG_TAG, "startActivity() called");
        } catch (Exception e)
        {
            e.printStackTrace();
        }

below is my logcat log

WARN/dalvikvm(582): threadid=3: thread exiting with uncaught exception
(group=0x4001b188)
DEBUG/ErrorReporter(582): uncaughtException() tThread[main,5,main],
except:java.lang.RuntimeException: Unable to create service
com.my.service: java.lang.NullPointerException
INFO/ActivityManager(53): Starting activity: Intent
{ act=android.intent.action.CHOOSER flg=0x10000000 cmp=android/
com.android.internal.app.ChooserActivity (has extras) }
DEBUG/ErrorReporter(582): startActivity() called
ERROR/AndroidRuntime(582): Uncaught handler: thread main exiting due
to uncaught exception
ERROR/AndroidRuntime(582): java.lang.RuntimeException: Unable to
create service com.my.service: java.lang.NullPointerException
ERROR/AndroidRuntime(582):     at
android.app.ActivityThread.handleCreateService(ActivityThread.java:
2790)
ERROR/AndroidRuntime(582):     at android.app.ActivityThread.access
$3200(ActivityThread.java:119)
ERROR/AndroidRuntime(582):     at android.app.ActivityThread
$H.handleMessage(ActivityThread.java:1917)
ERROR/AndroidRuntime(582):     at
android.os.Handler.dispatchMessage(Handler.java:99)
ERROR/AndroidRuntime(582):     at android.os.Looper.loop(Looper.java:
123)
ERROR/AndroidRuntime(582):     at
android.app.ActivityThread.main(ActivityThread.java:4363)
ERROR/AndroidRuntime(582):     at
java.lang.reflect.Method.invokeNative(Native Method)
ERROR/AndroidRuntime(582):     at
java.lang.reflect.Method.invoke(Method.java:521)
ERROR/AndroidRuntime(582):     at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
ERROR/AndroidRuntime(582):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
ERROR/AndroidRuntime(582):     at
dalvik.system.NativeStart.main(Native Method)
ERROR/AndroidRuntime(582): Caused by: java.lang.NullPointerException
ERROR/AndroidRuntime(582):     at
com.my.service.onCreate(ISPService.java:230)
ERROR/AndroidRuntime(582):     at
android.app.ActivityThread.handleCreateService(ActivityThread.java:
2780)
ERROR/AndroidRuntime(582):     ... 10 more
INFO/Process(53): Sending signal. PID: 582 SIG: 3
INFO/dalvikvm(582): threadid=7: reacting to signal 3
INFO/dalvikvm(582): Wrote stack trace to '/data/anr/traces.txt'

I can't know why.

--



i can't send email in UncaughtExceptionHandler for Service

by Joseph Earl » Thu, 29 Jul 2010 20:06:51 GMT


 Here's your error:

java.lang.NullPointerException at
com.my.service.onCreate(ISPService.java line:230)

Take a look at line 230 of ISPService.java and try and see what could
possibly be null.




--



Other Threads

1. Is it possible to upgrade HTC Magic G2 from 1.5-Cupcake to 1.6-Donut ?

At some point, when 1.6 is finished, the update will be pushed to your
phone and it will ask you if you want to update.

Otherwise I think you can either flash your phone or apply the update
manually.



--~--~---------~--~----~------------~-------~--~----~

2. Mediastore Thumbnails not generated until Gallery app is launched ?

Is that normal that Images indexed in the MediaStore do not have
thumbnails generated until the Gallery app is launched and the user
actively navigates to the bucket where the image is stored ?

I think it's quite odd as I thought thulbnails generation was part of
media indexing.


--~--~---------~--~----~------------~-------~--~----~

3. Golf App for Android

4. documentation issue

5. download layoutlib.jar

6. record and store the recording to remote server

7. Sharing YM id, lagiii...