0
package com.testing.email;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class AndroidEmailActivity extends Activity implements OnClickListener{
/** Called when the activity is first created. */
String msg = "**********Backup Phone Contacts**********\n\n";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button send = (Button)findViewById(R.id.button1);
    send.setOnClickListener(this);
}

public void onClick(View view){

    ContentResolver cr = getContentResolver();
    Cursor cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);

    while(cursor.moveToNext()){
        String name = cursor.getString(cursor.getColumnIndexOrThrow(Phone.DISPLAY_NAME));
        String number = cursor.getString(cursor.getColumnIndexOrThrow(Phone.NUMBER));

        msg += name + "\t\t\t" + number + "\n";         
    }

    String emailAddress = "testing@hotmail.com";
    String emailSubject = "Testing";
    String emailText = msg;

    String emailAddressList[] = {emailAddress};

    Intent intent = new Intent(Intent.ACTION_SEND); 
    intent.setType("plain/text");
    intent.putExtra(Intent.EXTRA_EMAIL, emailAddressList);  
    intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject); 
    intent.putExtra(Intent.EXTRA_TEXT, emailText); 
    startActivity(Intent.createChooser(intent, "Android apps send email:"));
    }
}

Logcat

10-16 13:18:41.435: E/ActivityThread(732): Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@41071180 that was originally registered here. Are you missing a call to unregisterReceiver()?
10-16 13:18:41.435: E/ActivityThread(732): android.app.IntentReceiverLeaked: Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@41071180 that was originally registered here. Are you missing a call to unregisterReceiver()?
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:763)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:567)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1043)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.ContextImpl.registerReceiver(ContextImpl.java:1030)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.ContextImpl.registerReceiver(ContextImpl.java:1024)
10-16 13:18:41.435: E/ActivityThread(732):  at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:341)
10-16 13:18:41.435: E/ActivityThread(732):  at com.android.internal.content.PackageMonitor.register(PackageMonitor.java:65)
10-16 13:18:41.435: E/ActivityThread(732):  at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:99)
10-16 13:18:41.435: E/ActivityThread(732):  at com.android.internal.app.ChooserActivity.onCreate(ChooserActivity.java:53)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.Activity.performCreate(Activity.java:4465)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
10-16 13:18:41.435: E/ActivityThread(732):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-16 13:18:41.435: E/ActivityThread(732):  at android.os.Looper.loop(Looper.java:137)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.ActivityThread.main(ActivityThread.java:4424)
10-16 13:18:41.435: E/ActivityThread(732):  at java.lang.reflect.Method.invokeNative(Native Method)
10-16 13:18:41.435: E/ActivityThread(732):  at java.lang.reflect.Method.invoke(Method.java:511)
10-16 13:18:41.435: E/ActivityThread(732):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-16 13:18:41.435: E/ActivityThread(732):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-16 13:18:41.435: E/ActivityThread(732):  at dalvik.system.NativeStart.main(Native Method)

I am developing an apps where user able to retrieve back all the phone contacts when the phone is lost or stolen using email. I am just testing on some simple coding and try to retrieve all the contacts numbers and put them into a message and send to a defined email address. I am using Android emulator to test this and I already save 5 sample contacts in the emulator for the experiment. But when i received the email sent from this apps, i received more than 5 contact numbers and there are many contact numbers which should not be in my emulator. I have attached my code and logcat, someone please help me to check it... thanks...

Android_Rookie
  • 509
  • 2
  • 10
  • 25

1 Answers1

0

There are more people having this problem with certain android versions:

Android bug

SO Question 1

SO Question 2

SO Question 3

And more :)

Community
  • 1
  • 1
Ion Aalbers
  • 7,830
  • 3
  • 37
  • 50
  • Your app doesn't crash by this so I guess you can just leave it? – Ion Aalbers Oct 16 '12 at 14:15
  • Or is there anything wrong with my coding, because I just have 5 contacts in the emulator, should be sending only 5 contacts to the email, but I received MANY contacts in the email and most of the contacts are not from the emulator... – Android_Rookie Oct 16 '12 at 14:20