Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8755777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:55:20+00:00 2026-06-13T13:55:20+00:00

I am building an Android app through which i want to instantly mail the

  • 0

I am building an Android app through which i want to instantly mail the photos taken from device camera.
I want this to be done in Background, so i used JAVA Mail API, and I am starting a service to mail the images.

Till now my code is working fine with images < 50 KB , but it is throwing weird error when I am trying to mail image >= 500 KB .
for now i am using hardcoded values for files and username, password.

Code of my background Service :-

public class BgMailer extends Service{

private ArrayList<String>Recievers ;
private String msg,sub;
public void onCreate() {
    // TODO Auto-generated method stub
    //Toast.makeText(getApplicationContext(), "service created",5000).show();


    super.onCreate();

}


@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    //Toast.makeText(this, DataHolder., duration)
    //sendMail();
      Notification note = new Notification( 0, null, System.currentTimeMillis() );
        note.flags |= Notification.FLAG_NO_CLEAR;
        startForeground( 42, note );

    Recievers = intent.getStringArrayListExtra("recievers");
    sub = intent.getStringExtra("sub");
    msg = intent.getStringExtra("msg");

    sendMail(Recievers, sub, msg);
//  stopForeground(true);

    this.stopSelf();
    return super.onStartCommand(intent, flags, startId);

}


@Override
public void onDestroy() {
    // TODO Auto-generated method stub
    //Toast.makeText(getApplicationContext(), "service destroyed",5000).show();
    super.onDestroy();
}


@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}

public  void sendMail(ArrayList<String>recvr,String sub,String msg){
     Mail m = new Mail("r4jiv007@gmail.com", "<password>");

     String [] address = new String[recvr.size()];
        address = recvr.toArray(address);
        m.set_to(address);
        m.set_from("r4jiv007@gmail.com");
        m.set_subject(sub);
        m.setBody(msg);

        try {
             m.addAttachment("/sdcard/1.jpg");
           //m.addAttachment("/sdcard/1.txt");
     //     m.addAttachment("/sdcard/bday.jpg");
          if(m.send()) {
            Toast.makeText(getApplicationContext(), "Email was sent successfully.", Toast.LENGTH_LONG).show();
          } else {
            Toast.makeText(getApplicationContext(), "Email was not sent.", Toast.LENGTH_LONG).show();
          }
        } catch(Exception e) {
          Log.e("MailApp", "Could not send email", e);
        } 
}

}

Error values in LogCat :-

10-20 01:34:13.690: W/ActivityManager(134): Timeout executing service: 
ServiceRecord{40ae01d0 my.com.cnm/.BgMailer}
10-20 01:34:13.800: I/Process(134): Sending signal. PID: 1845 SIG: 3
10-20 01:34:13.800: I/dalvikvm(1845): threadid=4: reacting to signal 3
10-20 01:34:13.820: I/dalvikvm(1845): Wrote stack traces to '/data/anr/traces.txt'
10-20 01:34:13.830: I/Process(134): Sending signal. PID: 134 SIG: 3
10-20 01:34:13.830: I/dalvikvm(134): threadid=4: reacting to signal 3
10-20 01:34:13.870: I/dalvikvm(134): Wrote stack traces to '/data/anr/traces.txt'
10-20 01:34:13.870: I/Process(134): Sending signal. PID: 235 SIG: 3
10-20 01:34:13.870: I/dalvikvm(235): threadid=4: reacting to signal 3
10-20 01:34:13.880: I/dalvikvm(235): Wrote stack traces to '/data/anr/traces.txt'
10-20 01:34:13.880: I/Process(134): Sending signal. PID: 239 SIG: 3
10-20 01:34:13.880: I/dalvikvm(239): threadid=4: reacting to signal 3
10-20 01:34:13.900: I/dalvikvm(239): Wrote stack traces to '/data/anr/traces.txt'
10-20 01:34:13.900: I/Process(134): Sending signal. PID: 208 SIG: 3
10-20 01:34:13.900: I/dalvikvm(208): threadid=4: reacting to signal 3
10-20 01:34:13.900: I/dalvikvm(208): Wrote stack traces to '/data/anr/traces.txt'
10-20 01:34:14.481: D/dalvikvm(134): GC_CONCURRENT freed 1427K, 32% free 9016K/13191K, external 607K/1119K, paused 8ms+16ms
10-20 01:34:14.821: D/dalvikvm(134): GC_EXPLICIT freed 379K, 32% free 9072K/13191K, external 607K/1119K, paused 171ms
10-20 01:34:15.432: I/Process(134): Sending signal. PID: 1657 SIG: 3
10-20 01:34:15.432: I/dalvikvm(1657): threadid=4: reacting to signal 3
10-20 01:34:15.432: I/dalvikvm(1657): Wrote stack traces to '/data/anr/traces.txt'
10-20 01:34:15.442: E/ActivityManager(134): ANR in my.com.cnm:Bgmailer time=4035592
10-20 01:34:15.442: E/ActivityManager(134): Reason: Executing service my.com.cnm/.BgMailer
10-20 01:34:15.442: E/ActivityManager(134): Load: 3.78 / 3.97 / 3.79
10-20 01:34:15.442: E/ActivityManager(134): CPU usage from 13492ms to 0ms ago with 99% awake:
10-20 01:34:15.442: E/ActivityManager(134):   1.4% 230/com.htc.android.htcime: 1.3% user + 0% kernel / faults: 746 minor 3 major
10-20 01:34:15.442: E/ActivityManager(134):   4% 1845/my.com.cnm:Bgmailer: 3.7% user + 0.3% kernel / faults: 63 minor
10-20 01:34:15.442: E/ActivityManager(134):   2.2% 239/android.process.acore: 2.1% user + 0% kernel / faults: 12 minor
10-20 01:34:15.442: E/ActivityManager(134):   1.5% 272/dhd_dpc: 0% user + 1.5% kernel
10-20 01:34:15.442: E/ActivityManager(134):   1.2% 134/system_server: 0.7% user + 0.5% kernel
10-20 01:34:15.442: E/ActivityManager(134):   0.8% 81/akmd: 0% user + 0.8% kernel
10-20 01:34:15.442: E/ActivityManager(134):   0.6% 1657/my.com.cnm: 0.3% user + 0.2% kernel / faults: 4 minor
10-20 01:34:15.442: E/ActivityManager(134):   0.5% 424/com.android.htccontacts: 0.5% user + 0% kernel / faults: 54 minor
10-20 01:34:15.442: E/ActivityManager(134):   0.1% 208/com.android.systemui: 0% user + 0% kernel
10-20 01:34:15.442: E/ActivityManager(134):   0% 271/dhd_watchdog: 0% user + 0% kernel
10-20 01:34:15.442: E/ActivityManager(134):   0% 5/events/0: 0% user + 0% kernel
10-20 01:34:15.442: E/ActivityManager(134):   0% 14/kondemand/0: 0% user + 0% kernel
10-20 01:34:15.442: E/ActivityManager(134):   0% 64/kgsl-3d0/0: 0% user + 0% kernel
10-20 01:34:15.442: E/ActivityManager(134):   0% 83/adbd: 0% user + 0% kernel
10-20 01:34:15.442: E/ActivityManager(134):   0% 291/wpa_supplicant: 0% user + 0% kernel
10-20 01:34:15.442: E/ActivityManager(134):   0% 552/com.ebuddy.android.xms: 0% user + 0% kernel
10-20 01:34:15.442: E/ActivityManager(134):   0% 753/com.google.android.apps.maps:NetworkLocationService: 0% user + 0% kernel
10-20 01:34:15.442: E/ActivityManager(134):   0.1% 848/com.google.android.apps.maps:LocationFriendService: 0% user + 0% kernel + 0%         iowait
10-20 01:34:15.442: E/ActivityManager(134): 19% TOTAL: 16% user + 2.3% kernel + 0.3% iowait + 0.1% softirq
10-20 01:34:15.442: E/ActivityManager(134): CPU usage from 1133ms to 1688ms later:
10-20 01:34:15.442: E/ActivityManager(134):   8.9% 134/system_server: 0% user + 8.9% kernel
10-20 01:34:15.442: E/ActivityManager(134):     5.3% 157/ActivityManager: 0% user + 5.3% kernel
10-20 01:34:15.442: E/ActivityManager(134):     1.7% 140/SurfaceFlinger: 1.7% user + 0% kernel
10-20 01:34:15.442: E/ActivityManager(134):   1.7% 81/akmd: 1.7% user + 0% kernel
10-20 01:34:15.442: E/ActivityManager(134):     3.5% 1722/akmd: 3.5% user + 0% kernel
10-20 01:34:15.442: E/ActivityManager(134):   1.2% 1657/my.com.cnm: 1.2% user + 0% kernel / faults: 2 minor
10-20 01:34:15.442: E/ActivityManager(134): 14% TOTAL: 5.3% user + 8.9% kernel
10-20 01:34:15.452: I/Process(134): Sending signal. PID: 1845 SIG: 9
10-20 01:34:15.452: I/ActivityManager(134): Skipping background ANR: my.com.cnm:Bgmailer time=4035592
10-20 01:34:15.462: I/ActivityManager(134): Process my.com.cnm:Bgmailer (pid 1845) has died.

is there any thing related to priority or service here, i even tried to run my service as a foreground application , but of no use .. and i am not able to figure out how to solve this.
i would appreciate any help in this !!

thanks 🙂

well thanks for the suggestion for this problem , i just created a thread and mailed the image through it and it was successful .. but i want to show a toast when the mailing process completed successfully but i am getting following error :-

 E/MailApp(2131): Could not send email
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:121)
at android.widget.Toast.<init>(Toast.java:68)
at android.widget.Toast.makeText(Toast.java:231)
at my.com.cnm.BgMailer.sendMail(BgMailer.java:86)
at my.com.cnm.BgMailer$1.run(BgMailer.java:47)
at java.lang.Thread.run(Thread.java:1027)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:55:22+00:00Added an answer on June 13, 2026 at 1:55 pm

    Since service also run in process main thread you might try to create separate thread in the service to send the email..

    following is from the official doc:

    Note that services, like other application objects, run in the main thread of their hosting process. This means that, if your service is going to do any CPU intensive (such as MP3 playback) or blocking (such as networking) operations, it should spawn its own thread in which to do that work.

    check out the accepted answer in the following post to show the Toast from background thread:

    Android: How can i show a toast from a thread running in a remote service?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Building our Android app from Ant fails with this error: [apply] [apply] UNEXPECTED TOP-LEVEL
I am building this android app for jogging which is supposed to measure the
Problem: I am building Android app in Eclipse which uses shared lib libgstreamer-0.10.so (GStreamer-android
I am building an android app, and I want to be able to have
I'm building a fairly simple Android app (sdk revision 14: ICS) which allows users
I'm building a zip code search page for my Android app so I want
I am building an android app for which I need to check the sync
I'm building an Android app that will stream several radio stations from a Latin
I'm building an Android app (so machines with limited resources) and I want to
I'm building an android app who needs to present lots of data received from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.