Intents
Qué es un intent?
Los intents: tipos y ejemplos (punto 7 de la unidad 2)
Intents en developer.android.com
Verificar que existe al menos una actividad para lanzar el intent
Intent sendIntent = new Intent(Intent.ACTION_SEND); ... // Always use string resources for UI text. // This says something like "Share this photo with" String title = getResources().getString(R.string.chooser_title); // Create intent to show the chooser dialog Intent chooser = Intent.createChooser(sendIntent, title); // Verify the original intent will resolve to at least one activity if (sendIntent.resolveActivity(getPackageManager()) != null) { startActivity(chooser); }
Ejemplo de intent implícito
public void openWebPage(String url) { Uri webpage = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, webpage); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } else { Toast.makeText(this, "Error al lanzar el intent", Toast.LENGTH_SHORT).show(); } }
Ejemplo de intent explícito
intent = new Intent(this, SecondActivity.class); Bundle extras = new Bundle(); extras.putString("usuario", "Carmelo Cotón); extras.putInt("edad", 27); intent.putExtras(extras); startActivity(intent);
Ejemplo: Comunicación de actividades mediante intents
Código de Comunicacion de actividades
Ejercicio 2 de la tarea online
Más información:
Comunicar actividades a través de Intents
Deja una respuesta
Lo siento, debes estar conectado para publicar un comentario.