Your code violates a couple of accepted coding practices but not necessarily MVC. Here is how I would re-factor it so that it is DRY and follows LoD.
public static Intent prepare( String to, String cc, String subject, String content, String messageType )
{
if (messageType==null){ messageType = "plain/text"; }
Intent preparedIntent = new Intent( Intent.ACTION_SEND );
preparedIntent.setType( messageType );
if (to!=null) {
preparedIntent.putExtra(Intent.EXTRA_EMAIL, new String[ ]
{
to
});
}
if (cc!=null) {
preparedIntent.putExtra(Intent.EXTRA_CC, new String[ ]
{
cc
});
}
preparedIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
preparedIntent.putExtra(Intent.EXTRA_TEXT, content);
return preparedIntent;
}
This way, you don't have to reference a specific type of control (EditText
) and you can re-use this static method anywhere you need to create an email Intent