Android™
Android™
Clear an Email Object
See more Email Object Examples
Demonstrates the Chilkat Email.Clear method, which removes the current message content — recipients, headers, body representations, attachments, related items, and embedded messages — leaving an empty email object. This example builds a message with a recipient and attachment, clears it, and prints the counts before and after.
Background: Reusing a single
Email object across many operations is efficient, but leftover state from a previous message could leak into the next. Clear resets the object completely, giving you a clean slate — the safe way to start a fresh message without allocating a new object.Chilkat Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Demonstrates the Clear method, which removes the current message content, including
// recipients, headers, body representations, attachments, related items, and embedded
// messages -- leaving an empty email object.
CkEmail email = new CkEmail();
email.put_Subject("A message");
email.put_Body("Some body text.");
email.AddTo("Bob","bob@example.com");
email.AddStringAttachment("notes.txt","Some notes.");
Log.i(TAG, "NumTo before clear = " + String.valueOf(email.get_NumTo()));
Log.i(TAG, "NumAttachments before clear = " + String.valueOf(email.get_NumAttachments()));
// Remove all content, resetting the email object.
email.Clear();
Log.i(TAG, "NumTo after clear = " + String.valueOf(email.get_NumTo()));
Log.i(TAG, "NumAttachments after clear = " + String.valueOf(email.get_NumAttachments()));
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}