เป็นรูปแบบการใช้งาน Intent ที่ไม่ได้ระบุ Component หรือ Class อย่างเจาะจง จะเป็นตัวไหนก็ได้ ขอแค่ตรงกับเงื่อนไขที่กำหนดไว้ก็พอ ซึ่งเงื่อนไขที่ว่าก็คือ Action, Type และ Category
Code: Select all
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Hello World");
intent.setType("text/plain");
startActivity(intent);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Hello World");
intent.setType("text/plain");
startActivity(intent);
เป็นรูปแบบการใช้งาน Intent ที่มีการระบุ Component หรือ Class ปลายทางอย่างเจาะจง
Code: Select all
String packageName = "com.google.android.apps.photos";
String className = "com.google.android.apps.photos.home.HomeActivity";
Intent intent = new Intent(packageName, className);
startActivity(intent);
Intent intent = new Intent();
intent.setClass(packageName, className);
startActivity(intent);
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, className));
startActivity(intent);