// starting an activity from another activity
// this is a Activity context
Intent intent = new Intent(this, AnotherActivity.java);
intent.putExtra(Intent.EXTRA_TEXT, "some text");
intent.putExtra("id", 4);
startActivity(intent);
// Receiving intent in AnotherActivity
Bundle extras = getIntent().getExtras();
if (extras == null) {
return;
}
// get data via the key
String value1 = extras.getString(Intent.EXTRA_TEXT);
if (value1 != null) {
// do something with the data
}
// Starting a service
Intent intent = new Intent(this, HelloService.class);
startService(intent);
// Sending a broadcast
Intent intent = new Intent();
intent.setAction("com.example.broadcast.MY_NOTIFICATION");
intent.putExtra("data", "Notice me senpai!");
sendBroadcast(intent);