Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setType("plain/text");
sendIntent.setData(Uri.parse("test@gmail.com"));
sendIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "test@gmail.com" });
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "test");
sendIntent.putExtra(Intent.EXTRA_TEXT, "hello. this is a message sent from my demo app :-)");
startActivity(sendIntent);
In the code above (from this answer by Jared Burrows) I am confused why we have to specify the action: ACTION_VIEW in the sendIntent definition? We already specified that the activity that we want to start using the sendIntent intent is the "com.google.android.gm", "com.google.android.gm.ComposeActivityGmail" activity.
I thought the only purpose of the action ACTION_VIEW would be if you are making an implicit intent and you want the system to display all of the applications that the user downloaded that have an Activity that can perform the action ACTION_VIEW?
But in this case we already specified which activity we want to start which is ComposeActivityGmail so why put the ACTION_CLOSE action since the system would already which activity to start for this intent.