Académique Documents
Professionnel Documents
Culture Documents
Communication entre
applications
(Les objets Intent)
Développement mobile sous Android
<application ...>
<activity android:name=".EnafantActivity" />
</application>
Developpement mobile sous
6
Android
Exemple de startActivity()
• Fichier: parent_layout.xml • Fichier: enfant1_layout.xml
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android= <LinearLayout xmlns:android=
"http://schemas.android.com/apk/res/a "http://schemas.android.com/apk/res/
ndroid" android"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
> >
<Button <TextView
android:layout_width="fill_parent"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:text="Bienvenu dans l'activité
android:text="Appel de l'activité Enfant1 "
Enfant1" />
android:id="@+id/bouton"/> </LinearLayout>
</LinearLayout>
B_OK=(Button)findViewById(R.id.boutonOK2);
B_AN=(Button)findViewById(R.id.boutonANNULER2
);
B_OK.setOnClickListener (new OnClickListener () {
public void onClick (View view) {
setResult(RESULT_OK);
finish();
}
});
B_AN.setOnClickListener (new OnClickListener () {
public void onClick (View view) {
setResult(RESULT_CANCELED);
finish();
}
});
}
}
• Exemple 2:
Uri uri = Uri.parse("tel:0612345678");
Intent intent = new Intent(Intent.ACTION_CALL, uri);
startActivity(intent);
• Exemple:
<activity ...
<intent-filter>
<action
android:name="android.intent.action.VIEW" />
<category
android:name="android.intent.category.DEFAULT"/>
<category
android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="demo" />
</intent-filter>
</activity>